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.graphaware.importer.data.access.DbDataReader.java
/** * Create a {@link javax.sql.DataSource} used for talking to the database. * * @return data source.//from w w w . java 2 s.com */ protected DataSource createDataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setUrl(getUrl(dbHost, dbPort)); dataSource.setUsername(user); dataSource.setPassword(password); dataSource.setDefaultReadOnly(true); dataSource.setDefaultAutoCommit(false); dataSource.setDriverClassName(getDriverClassName()); additionalConfig(dataSource); return dataSource; }
From source file:at.rocworks.oa4j.logger.dbs.NoSQLJDBC.java
private void initStorage(BasicDataSource dataSource, int threads) { JDebug.out.info("jdbc init storage..."); dataSource.setDriverClassName(driver); dataSource.setUrl(this.url); dataSource.setMaxTotal(threads);// w w w . j a va 2s . c om dataSource.setUsername(username); dataSource.setPassword(password); JDebug.out.info("jdbc get connection..."); // open at least one connection to prevent delay on writing/reading Connection conn; try { conn = dataSource.getConnection(); conn.close(); } catch (SQLException ex) { JDebug.StackTrace(Level.SEVERE, ex); } JDebug.out.info("jdbc init storage...done"); }
From source file:moviemanager.backend.SpringConfig.java
@Bean public DataSource dataSource() { /*BasicDataSource bds = new BasicDataSource(); //Apache DBCP connection pooling DataSource bds.setDriverClassName(env.getProperty("jdbc.driver")); bds.setUrl(env.getProperty("jdbc.url")); bds.setUsername(env.getProperty("jdbc.user")); bds.setPassword(env.getProperty("jdbc.password")); return bds;*/// w w w . j a va2s .c om /*Properties conf = new Properties(); BasicDataSource ds = new BasicDataSource(); try { conf.load(SpringConfig.class.getResourceAsStream("/myconf.properties")); } catch (IOException ex) { //log.error("Loading properties has failed!"); } try { DriverManager.getConnection(conf.getProperty("jdbc.url")); } catch (SQLException ex) { try { Connection conn = DriverManager.getConnection(conf.getProperty("jdbc.url"), conf.getProperty("jdbc.user"), conf.getProperty("jdbc.password")); //Connection conn = DriverManager.getConnection("org.apache.jdbc.ClientDriver" + "create=true;", "administrator", "admin"); } catch (SQLException ex1) { Logger.getLogger(SpringConfig.class.getName()).log(Level.SEVERE, null, ex1); } } ds.setUrl(conf.getProperty("jdbc.url")); return ds;*/ Properties conf = new Properties(); BasicDataSource ds = new BasicDataSource(); try { conf.load(SpringConfig.class.getResourceAsStream("/myconf.properties")); } catch (IOException ex) { //log.error("Loading properties has failed!"); } ds.setUrl(conf.getProperty("jdbc.url")); ds.setDriverClassName(conf.getProperty("jdbc.driver")); ds.setUsername(conf.getProperty("jdbc.user")); ds.setPassword(conf.getProperty("jdbc.password")); return ds; /* BasicDataSource bds = new BasicDataSource(); bds.setDriverClassName("org.apache.derby.jdbc.ClientDriver"); bds.setUrl("jdbc:derby://localhost:1527/MovieManagerDtb"); bds.setUsername("administrator"); bds.setPassword("admin"); return bds;*/ /*return new EmbeddedDatabaseBuilder() .setType(DERBY) .build();*/ }
From source file:net.gcolin.simplerepo.search.SearchController.java
public SearchController(ConfigurationManager configManager) throws IOException { this.configManager = configManager; File plugins = new File(configManager.getRoot(), "plugins"); plugins.mkdirs();//from ww w . ja v a2 s .c om System.setProperty("derby.system.home", plugins.getAbsolutePath()); BasicDataSource s = new BasicDataSource(); s.setDriverClassName("org.apache.derby.jdbc.EmbeddedDriver"); s.setUrl("jdbc:derby:search" + (new File(plugins, "search").exists() ? "" : ";create=true")); s.setUsername("su"); s.setPassword(""); s.setMaxTotal(10); s.setMinIdle(0); s.setDefaultAutoCommit(true); datasource = s; Set<String> allTables = new HashSet<>(); Connection connection = null; try { try { connection = datasource.getConnection(); connection.setAutoCommit(false); DatabaseMetaData dbmeta = connection.getMetaData(); try (ResultSet rs = dbmeta.getTables(null, null, null, new String[] { "TABLE" })) { while (rs.next()) { allTables.add(rs.getString("TABLE_NAME").toLowerCase()); } } if (!allTables.contains("artifact")) { QueryRunner run = new QueryRunner(); run.update(connection, "CREATE TABLE artifactindex(artifact bigint NOT NULL, version bigint NOT NULL)"); run.update(connection, "INSERT INTO artifactindex (artifact,version) VALUES (?,?)", 1L, 1L); run.update(connection, "CREATE TABLE artifact(id bigint NOT NULL,groupId character varying(120), artifactId character varying(120),CONSTRAINT artifact_pkey PRIMARY KEY (id))"); run.update(connection, "CREATE TABLE artifactversion(artifact_id bigint NOT NULL,id bigint NOT NULL," + "version character varying(100)," + "reponame character varying(30)," + "CONSTRAINT artifactversion_pkey PRIMARY KEY (id)," + "CONSTRAINT fk_artifactversion_artifact_id FOREIGN KEY (artifact_id) REFERENCES artifact (id) )"); run.update(connection, "CREATE TABLE artifacttype(version_id bigint NOT NULL,packaging character varying(20) NOT NULL,classifier character varying(30)," + "CONSTRAINT artifacttype_pkey PRIMARY KEY (version_id,packaging,classifier)," + "CONSTRAINT fk_artifacttype_version FOREIGN KEY (version_id) REFERENCES artifactversion (id))"); run.update(connection, "CREATE INDEX artifactindex ON artifact(groupId,artifactId)"); run.update(connection, "CREATE INDEX artifactgroupindex ON artifact(groupId)"); run.update(connection, "CREATE INDEX artifactversionindex ON artifactversion(version)"); } connection.commit(); } catch (SQLException ex) { connection.rollback(); throw ex; } finally { DbUtils.close(connection); } } catch (SQLException ex) { throw new IOException(ex); } }
From source file:com.thoughtworks.go.server.database.H2Database.java
private void configureDataSource(BasicDataSource source, String url) { String databaseUsername = configuration.getUser(); String databasePassword = configuration.getPassword(); LOG.info("[db] Using connection configuration {} [User: {}]", url, databaseUsername); source.setDriverClassName("org.h2.Driver"); source.setUrl(url);// w w w . j a va 2 s . co m source.setUsername(databaseUsername); source.setPassword(databasePassword); source.setMaxTotal(configuration.getMaxActive()); source.setMaxIdle(configuration.getMaxIdle()); }
From source file:com.norconex.collector.core.data.store.impl.jdbc.JDBCCrawlDataStore.java
private DataSource createDataSource(String dbDir) { BasicDataSource ds = new BasicDataSource(); if (database == Database.DERBY) { ds.setDriverClassName("org.apache.derby.jdbc.EmbeddedDriver"); ds.setUrl("jdbc:derby:" + dbDir + ";create=true"); } else {//from ww w . j a v a 2 s .c o m ds.setDriverClassName("org.h2.Driver"); ds.setUrl("jdbc:h2:" + dbDir + ";WRITE_DELAY=0;AUTOCOMMIT=ON"); } ds.setDefaultAutoCommit(true); return ds; }
From source file:com.emc.vipr.sync.filter.TrackingFilter.java
@Override public void parseCustomOptions(CommandLine line) { if (!line.hasOption(DB_URL_OPT)) throw new ConfigurationException("Must provide a database to use the tracking filter"); if (line.hasOption(TABLE_OPT)) tableName = line.getOptionValue(TABLE_OPT); createTable = line.hasOption(CREATE_TABLE_OPT); processAllObjects = line.hasOption(REPROCESS_OPT); if (line.hasOption(META_OPT)) metaTags = Arrays.asList(line.getOptionValue(META_OPT).split(",")); // Initialize a DB connection pool BasicDataSource ds = new BasicDataSource(); ds.setUrl(line.getOptionValue(DB_URL_OPT)); if (line.hasOption(DB_DRIVER_OPT)) ds.setDriverClassName(line.getOptionValue(DB_DRIVER_OPT)); ds.setUsername(line.getOptionValue(DB_USER_OPT)); ds.setPassword(line.getOptionValue(DB_PASSWORD_OPT)); ds.setMaxTotal(200);/*from ww w . j a va 2 s . c o m*/ ds.setMaxOpenPreparedStatements(180); dataSource = ds; }
From source file:cz.muni.fi.pv168.project.hotelmanager.TestReservationManagerImpl.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:TestReservationManagerDB;create=true"); this.dataSource = bds; //populate db with tables and data new ResourceDatabasePopulator(new ClassPathResource("schema-javadb.sql")).execute(bds); guestManager = new GuestManagerImpl(bds); roomManager = new RoomManagerImpl(bds); reservationManager = new ReservationManagerImpl(prepareClockMock(now), bds); }
From source file:de.micromata.genome.util.runtime.LocalSettingsEnv.java
/** * Parses the ds.//from w w w .j av a 2s . c o m */ protected void parseDs() { // db.ds.rogerdb.name=RogersOracle // db.ds.rogerdb.drivername=oracle.jdbc.driver.OracleDriver // db.ds.rogerdb.url=jdbc:oracle:thin:@localhost:1521:rogdb // db.ds.rogerdb.username=genome // db.ds.rogerdb.password=genome List<String> dse = localSettings.getKeysPrefixWithInfix("db.ds", "name"); for (String dsn : dse) { String key = dsn + ".name"; String name = localSettings.get(key); if (StringUtils.isBlank(name) == true) { log.error("Name in local-settings is not defined with key: " + key); continue; } key = dsn + ".drivername"; String driverName = localSettings.get(key); if (StringUtils.isBlank(name) == true) { log.error("drivername in local-settings is not defined with key: " + key); continue; } key = dsn + ".url"; String url = localSettings.get(key); if (StringUtils.isBlank(name) == true) { log.error("url in local-settings is not defined with key: " + key); continue; } key = dsn + ".username"; String userName = localSettings.get(key); key = dsn + ".password"; String password = localSettings.get(key); BasicDataSource bd = dataSourceSuplier.get(); bd.setDriverClassName(driverName); bd.setUrl(url); bd.setUsername(userName); bd.setPassword(password); bd.setMaxTotal(localSettings.getIntValue(dsn + ".maxActive", GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL_PER_KEY)); bd.setMaxIdle(localSettings.getIntValue(dsn + ".maxIdle", GenericKeyedObjectPoolConfig.DEFAULT_MAX_IDLE_PER_KEY)); bd.setMinIdle(localSettings.getIntValue(dsn + ".minIdle", GenericKeyedObjectPoolConfig.DEFAULT_MIN_IDLE_PER_KEY)); bd.setMaxWaitMillis(localSettings.getLongValue(dsn + ".maxWait", GenericKeyedObjectPoolConfig.DEFAULT_MAX_WAIT_MILLIS)); bd.setInitialSize(localSettings.getIntValue(dsn + ".intialSize", 0)); bd.setDefaultCatalog(localSettings.get(dsn + ".defaultCatalog", null)); bd.setDefaultAutoCommit(localSettings.getBooleanValue(dsn + ".defaultAutoCommit", true)); bd.setValidationQuery(localSettings.get(dsn + ".validationQuery", null)); bd.setValidationQueryTimeout(localSettings.getIntValue(dsn + ".validationQueryTimeout", -1)); dataSources.put(name, bd); } }
From source file:com.dsf.dbxtract.cdc.journal.JournalExecutor.java
/** * @param agentName//from w ww.ja v a2 s.com * cdc agent's assigned name * @param zookeeper * connection string to ZooKeeper server * @param handler * {@link JournalHandler} * @param source * {@link Source} */ public JournalExecutor(String agentName, String zookeeper, JournalHandler handler, Source source) { logPrefix = agentName + " :: "; if (logger.isDebugEnabled()) logger.debug(logPrefix + "Creating executor for " + handler + " and " + source); this.agentName = agentName; this.zookeeper = zookeeper; this.handler = handler; this.source = source; BasicDataSource ds = dataSources.get(source); if (ds == null) { if (logger.isDebugEnabled()) logger.debug(agentName + " :: setting up a connection pool for " + source.toString()); ds = new BasicDataSource(); ds.setDriverClassName(source.getDriver()); ds.setUsername(source.getUser()); ds.setPassword(source.getPassword()); ds.setUrl(source.getConnection()); dataSources.put(source, ds); } if (statistics == null) statistics = new Statistics(); }