List of usage examples for org.apache.commons.dbcp2 BasicDataSource setDriverClassName
public synchronized void setDriverClassName(String driverClassName)
Sets the jdbc driver class name.
Note: this method currently has no effect once the pool has been initialized.
From source file:com.zaxxer.hikari.benchmark.BenchBase.java
private void setupDBCP2basic() throws SQLException { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(dbDriver); ds.setUsername("sa"); ds.setPassword(""); ds.setUrl(jdbcURL);/*w w w.ja v a2s .c om*/ ds.setMaxTotal(maxPoolSize); ds.setDefaultAutoCommit(false); ds.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); ds.getConnection().createStatement().execute("CREATE TABLE IF NOT EXISTS test (column varchar);"); DS = ds; }
From source file:com.dsf.dbxtract.cdc.AppJournalDeleteTest.java
/** * Rigourous Test :-)//from ww w. j a v a2 s. co m * * @throws Exception * in case of any error */ @Test(timeOut = 120000) public void testAppWithJournalDelete() throws Exception { final Config config = new Config(configFile); BasicDataSource ds = new BasicDataSource(); Source source = config.getDataSources().getSources().get(0); ds.setDriverClassName(source.getDriver()); ds.setUsername(source.getUser()); ds.setPassword(source.getPassword()); ds.setUrl(source.getConnection()); // prepara os dados Connection conn = ds.getConnection(); conn.createStatement().execute("truncate table test"); conn.createStatement().execute("truncate table j$test"); // Carrega os dados de origem PreparedStatement ps = conn.prepareStatement("insert into test (key1,key2,data) values (?,?,?)"); for (int i = 0; i < TEST_SIZE; i++) { if ((i % 100) == 0) { ps.executeBatch(); } ps.setInt(1, i); ps.setInt(2, i); ps.setInt(3, (int) Math.random() * 500); ps.addBatch(); } ps.executeBatch(); ps.close(); app = new App(config); app.start(); Assert.assertEquals(config.getHandlers().iterator().next().getStrategy(), JournalStrategy.DELETE); // Popula as tabelas de journal ps = conn.prepareStatement("insert into j$test (key1,key2) values (?,?)"); for (int i = 0; i < TEST_SIZE; i++) { if ((i % 500) == 0) { ps.executeBatch(); } ps.setInt(1, i); ps.setInt(2, i); ps.addBatch(); } ps.executeBatch(); ps.close(); while (true) { TimeUnit.MILLISECONDS.sleep(500); ResultSet rs = conn.createStatement().executeQuery("select count(*) from j$test"); if (rs.next()) { long count = rs.getLong(1); System.out.println("remaining journal rows: " + count); rs.close(); if (count == 0L) break; } } conn.close(); ds.close(); }
From source file:cz.muni.fi.pv168.project.hotelmanager.RoomManagerImplTest.java
@Before public void setUp() throws SQLException { BasicDataSource bds = new BasicDataSource(); //set JDBC driver and URL bds.setDriverClassName(EmbeddedDriver.class.getName()); bds.setUrl("jdbc:derby:memory:TestRoomManagerDB;create=true"); //populate db with tables and data new ResourceDatabasePopulator(new ClassPathResource("schema-javadb.sql")).execute(bds); this.dataSource = bds; manager = new RoomManagerImpl(bds); }
From source file:eu.peppol.persistence.jdbc.OxalisDataSourceFactoryDbcpImplTest.java
@Test public void testBasicDataSource() throws Exception { String jdbcDriverClassPath = globalConfiguration.getJdbcDriverClassPath(); URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { new URL(jdbcDriverClassPath) }, Thread.currentThread().getContextClassLoader()); BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setDriverClassName(globalConfiguration.getJdbcDriverClassName()); basicDataSource.setUrl(globalConfiguration.getJdbcConnectionURI()); basicDataSource.setUsername(globalConfiguration.getJdbcUsername()); basicDataSource.setPassword(globalConfiguration.getJdbcPassword()); // Does not work in 1.4, fixed in 1.4.1 basicDataSource.setDriverClassLoader(urlClassLoader); try {/*from ww w. ja v a2s . c o m*/ Connection connection = basicDataSource.getConnection(); assertNotNull(connection); } catch (SQLException e) { // As expected when using DBCP 1.4 } }
From source file:com.peertopark.spring.data.SpringDataConfig.java
@Bean public DataSource dataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setUrl(dataSourceConfig.getJDBCUrl()); dataSource.setUsername(dataSourceConfig.getJDBCUser()); dataSource.setPassword(dataSourceConfig.getJDBCPassword()); dataSource.setDriverClassName(dataSourceConfig.getJDBCDriver()); dataSource.setMaxTotal(dataSourceConfig.getMaxConnections()); return dataSource; }
From source file:io.druid.metadata.storage.postgresql.PostgreSQLConnector.java
@Inject public PostgreSQLConnector(Supplier<MetadataStorageConnectorConfig> config, Supplier<MetadataStorageTablesConfig> dbTables) { super(config, dbTables); final BasicDataSource datasource = getDatasource(); // PostgreSQL driver is classloader isolated as part of the extension // so we need to help JDBC find the driver datasource.setDriverClassLoader(getClass().getClassLoader()); datasource.setDriverClassName("org.postgresql.Driver"); this.dbi = new DBI(datasource); log.info("Configured PostgreSQL as metadata storage"); }
From source file:io.druid.metadata.storage.mysql.MySQLConnector.java
@Inject public MySQLConnector(Supplier<MetadataStorageConnectorConfig> config, Supplier<MetadataStorageTablesConfig> dbTables) { super(config, dbTables); final BasicDataSource datasource = getDatasource(); // MySQL driver is classloader isolated as part of the extension // so we need to help JDBC find the driver datasource.setDriverClassLoader(getClass().getClassLoader()); datasource.setDriverClassName("com.mysql.jdbc.Driver"); // use double-quotes for quoting columns, so we can write SQL that works with most databases datasource.setConnectionInitSqls(ImmutableList.of("SET sql_mode='ANSI_QUOTES'")); this.dbi = new DBI(datasource); log.info("Configured MySQL as metadata storage"); }
From source file:io.druid.metadata.storage.sqlserver.SQLServerConnector.java
@Inject public SQLServerConnector(Supplier<MetadataStorageConnectorConfig> config, Supplier<MetadataStorageTablesConfig> dbTables) { super(config, dbTables); final BasicDataSource datasource = getDatasource(); datasource.setDriverClassLoader(getClass().getClassLoader()); datasource.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); this.dbi = new DBI(datasource); this.dbi.setStatementRewriter(new CustomStatementRewriter()); log.info("Configured Sql Server as metadata storage"); }
From source file:dragonrental.backend.DbConfig.java
public DataSource dataSource() { Properties conf = new Properties(); BasicDataSource ds = new BasicDataSource(); try {/*from w w w .j a v a 2 s. com*/ conf.load(DbConfig.class.getResourceAsStream("/Properties.properties")); } catch (IOException ex) { //log.error("Loading properties has failed!"); } ds.setUrl(conf.getProperty("db.url")); ds.setDriverClassName(conf.getProperty("db.driver")); ds.setUsername(conf.getProperty("db.user")); ds.setPassword(conf.getProperty("db.password")); DatabaseMetaData metaData; ResultSet tables; try (Connection connection = ds.getConnection()) { metaData = connection.getMetaData(); tables = metaData.getTables(null, null, "%", new String[] { "TABLE" }); //checks wheter there is any tables (will not create new tables if it finds ANY table) if (!tables.next()) { new ResourceDatabasePopulator(new ClassPathResource("schema-javadb.sql"), new ClassPathResource("test-data.sql")).execute(ds); } } catch (SQLException ex) { System.out.println("SQL Ex when checking for tables"); System.out.println(ex.getMessage()); } return ds; }
From source file:com.dsf.dbxtract.cdc.AppJournalWindowTest.java
/** * Rigourous Test :-)//from ww w . j a v a2 s .com * * @throws Exception * in case of any error */ @Test(dependsOnMethods = "setUp", timeOut = 120000) public void testAppWithJournalWindow() throws Exception { final Config config = new Config(configFile); BasicDataSource ds = new BasicDataSource(); Source source = config.getDataSources().getSources().get(0); ds.setDriverClassName(source.getDriver()); ds.setUsername(source.getUser()); ds.setPassword(source.getPassword()); ds.setUrl(source.getConnection()); // prepara os dados Connection conn = ds.getConnection(); conn.createStatement().execute("truncate table test"); conn.createStatement().execute("truncate table j$test"); // Carrega os dados de origem PreparedStatement ps = conn.prepareStatement("insert into test (key1,key2,data) values (?,?,?)"); for (int i = 0; i < TEST_SIZE; i++) { if ((i % 100) == 0) { ps.executeBatch(); } ps.setInt(1, i); ps.setInt(2, i); ps.setInt(3, (int) Math.random() * 500); ps.addBatch(); } ps.executeBatch(); ps.close(); // Popula as tabelas de journal ps = conn.prepareStatement("insert into j$test (key1,key2) values (?,?)"); for (int i = 0; i < TEST_SIZE; i++) { if ((i % 500) == 0) { ps.executeBatch(); } ps.setInt(1, i); ps.setInt(2, i); ps.addBatch(); } ps.executeBatch(); ps.close(); Long maxWindowId = 0L; ResultSet rs = conn.createStatement().executeQuery("select max(window_id) from j$test"); if (rs.next()) { maxWindowId = rs.getLong(1); System.out.println("maximum window_id loaded: " + maxWindowId); } rs.close(); conn.close(); ds.close(); // Clear any previous test String zkKey = "/dbxtract/cdc/" + source.getName() + "/J$TEST/lastWindowId"; if (client.checkExists().forPath(zkKey) != null) client.delete().forPath(zkKey); // starts monitor Monitor.getInstance(config); // start app app = new App(config); System.out.println(config.toString()); app.start(); Assert.assertEquals(config.getHandlers().iterator().next().getStrategy(), JournalStrategy.WINDOW); while (true) { TimeUnit.MILLISECONDS.sleep(500); try { Long lastWindowId = Long.parseLong(new String(client.getData().forPath(zkKey))); System.out.println("lastWindowId = " + lastWindowId); if (maxWindowId.longValue() == lastWindowId.longValue()) { System.out.println("expected window_id reached"); break; } } catch (NoNodeException nne) { System.out.println("ZooKeeper - no node exception :: " + zkKey); } } }