List of usage examples for org.apache.commons.dbcp BasicDataSource setPassword
public synchronized void setPassword(String password)
Sets the #password .
Note: this method currently has no effect once the pool has been initialized.
From source file:org.openbravo.test.system.SystemValidatorTest.java
private Database createDatabaseObject(Module module) { final Properties props = OBPropertiesProvider.getInstance().getOpenbravoProperties(); final BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(props.getProperty("bbdd.driver")); if (props.getProperty("bbdd.rdbms").equals("POSTGRE")) { ds.setUrl(props.getProperty("bbdd.url") + "/" + props.getProperty("bbdd.sid")); } else {/*from w ww. ja v a2s .com*/ ds.setUrl(props.getProperty("bbdd.url")); } ds.setUsername(props.getProperty("bbdd.user")); ds.setPassword(props.getProperty("bbdd.password")); Platform platform = PlatformFactory.createNewPlatformInstance(ds); platform.getModelLoader().setOnlyLoadTableColumns(true); if (module != null) { final String dbPrefix = module.getModuleDBPrefixList().get(0).getName(); final ExcludeFilter filter = DBSMOBUtil.getInstance() .getExcludeFilter(new File(props.getProperty("source.path"))); filter.addPrefix(dbPrefix); return platform.loadModelFromDatabase(filter, dbPrefix, true, module.getId()); } return platform.loadModelFromDatabase(null); }
From source file:org.openrdf.sail.generaldb.GeneralDBStore.java
protected DataSource lookupDataSource(String url, String user, String password) throws NamingException { if (url.startsWith("jdbc:")) { BasicDataSource ds = new BasicDataSource(); ds.setUrl(url);//w w w . ja va 2s. c om ds.setUsername(user); ds.setPassword(password); setBasicDataSource(ds); return ds; } return (DataSource) new InitialContext().lookup(url); }
From source file:org.openrdf.sail.rdbms.mysql.MySqlStore.java
@Override public void initialize() throws SailException { try {//from w ww. j a v a 2 s.c o m Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { throw new RdbmsException(e.toString(), e); } StringBuilder url = new StringBuilder(); url.append("jdbc:mysql:"); if (serverName != null) { url.append("//").append(serverName); if (portNumber > 0) { url.append(":").append(portNumber); } url.append("/"); } url.append(databaseName); url.append("?useUnicode=yes&characterEncoding=UTF-8"); for (Entry<String, String> e : getProperties().entrySet()) { url.append("&"); url.append(enc(e.getKey())); url.append("="); url.append(enc(e.getValue())); } BasicDataSource ds = new BasicDataSource(); ds.setUrl(url.toString()); if (user != null) { ds.setUsername(user); } else { ds.setUsername(System.getProperty("user.name")); } if (password != null) { ds.setPassword(password); } MySqlConnectionFactory factory = new MySqlConnectionFactory(); factory.setSail(this); factory.setDataSource(ds); setBasicDataSource(ds); setConnectionFactory(factory); super.initialize(); }
From source file:org.openrdf.sail.rdbms.postgresql.PgSqlStore.java
@Override public void initialize() throws SailException { try {// w w w . j av a 2 s. c om Class.forName("org.postgresql.Driver"); } catch (ClassNotFoundException e) { throw new RdbmsException(e.toString(), e); } StringBuilder url = new StringBuilder(); url.append("jdbc:postgresql:"); if (serverName != null) { url.append("//").append(serverName); if (portNumber > 0) { url.append(":").append(portNumber); } url.append("/"); } url.append(databaseName); Iterator<Entry<String, String>> iter; iter = getProperties().entrySet().iterator(); if (iter.hasNext()) { url.append("?"); } while (iter.hasNext()) { Entry<String, String> e = iter.next(); url.append(enc(e.getKey())); url.append("="); url.append(enc(e.getValue())); if (iter.hasNext()) { url.append("&"); } } BasicDataSource ds = new BasicDataSource(); ds.setUrl(url.toString()); if (user != null) { ds.setUsername(user); } else { ds.setUsername(System.getProperty("user.name")); } if (password != null) { ds.setPassword(password); } PgSqlConnectionFactory factory = new PgSqlConnectionFactory(); factory.setSail(this); factory.setDataSource(ds); setBasicDataSource(ds); setConnectionFactory(factory); super.initialize(); }
From source file:org.openrdf.sail.rdbms.RdbmsStore.java
private DataSource lookupDataSource(String url, String user, String password) throws NamingException { if (url.startsWith("jdbc:")) { BasicDataSource ds = new BasicDataSource(); ds.setUrl(url);/* ww w . j av a 2 s . c om*/ ds.setUsername(user); ds.setPassword(password); setBasicDataSource(ds); return ds; } return (DataSource) new InitialContext().lookup(url); }
From source file:org.orbisgis.geoserver.h2gis.datastore.H2GISDataStoreFactory.java
@Override protected DataSource createDataSource(Map params, SQLDialect dialect) throws IOException { String database = (String) DATABASE.lookUp(params); String host = (String) HOST.lookUp(params); Boolean mvcc = (Boolean) MVCC.lookUp(params); Boolean mvstore = (Boolean) MVSTORE.lookUp(params); BasicDataSource dataSource = new BasicDataSource(); if (host != null && !host.equals("")) { Integer port = (Integer) PORT.lookUp(params); if (port != null) { dataSource.setUrl("jdbc:h2:tcp://" + host + ":" + port + "/" + database); } else {//from w w w . ja va2 s .com dataSource.setUrl("jdbc:h2:tcp://" + host + "/" + database); } } else if (baseDirectory == null) { //use current working directory dataSource.setUrl("jdbc:h2:" + database + ";AUTO_SERVER=TRUE" + (mvcc != null ? (";MVCC=" + mvcc) : "") + (mvstore != null ? (";MVSTORE=" + mvstore) : "")); } else { //use directory specified if the patch is relative String location; if (!new File(database).isAbsolute()) { location = new File(baseDirectory, database).getAbsolutePath(); } else { location = database; } dataSource.setUrl("jdbc:h2:file:" + location + ";AUTO_SERVER=TRUE" + (mvcc != null ? (";MVCC=" + mvcc) : "") + (mvstore != null ? (";MVSTORE=" + mvstore) : "")); } String username = (String) USER.lookUp(params); if (username != null) { dataSource.setUsername(username); } String password = (String) PASSWD.lookUp(params); if (password != null) { dataSource.setPassword(password); } dataSource.setDriverClassName("org.h2.Driver"); dataSource.setPoolPreparedStatements(false); // if we got here the database has been created, now verify it has the H2GIS extension // and eventually try to create them JDBCDataStore closer = new JDBCDataStore(); Connection cx = null; try { cx = dataSource.getConnection(); //Add the spatial function if (!JDBCUtilities.tableExists(cx, "PUBLIC.GEOMETRY_COLUMNS")) { CreateSpatialExtension.initSpatialExtension(cx); } } catch (SQLException e) { throw new IOException("Failed to create the target database", e); } finally { closer.closeSafe(cx); } return new DBCPDataSource(dataSource); }
From source file:org.overlord.dtgov.devsvr.bpm.DTGovBpmDevServer.java
/** * Creates an in-memory datasource./*from w w w . j a va 2 s . c o m*/ * @throws SQLException */ private static DataSource createInMemoryDatasource() throws SQLException { System.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect"); BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(Driver.class.getName()); ds.setUsername("sa"); ds.setPassword(""); ds.setUrl("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1"); Connection connection = ds.getConnection(); connection.close(); return ds; }
From source file:org.owasp.dependencytrack.config.DatabaseConfiguration.java
@Bean public DataSource dataSource() { BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setDriverClassName(driverClassName); basicDataSource.setUsername(username); basicDataSource.setPassword(password); basicDataSource.setUrl(url);/* w w w. j a v a 2 s. co m*/ basicDataSource.setMaxActive(maxActive); return basicDataSource; }
From source file:org.owasp.dependencytrack.config.JunitDatabaseConfiguration.java
@Bean public DataSource dataSource() { BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setDriverClassName("org.h2.Driver"); basicDataSource.setUsername("sa"); basicDataSource.setPassword(""); basicDataSource.setUrl("jdbc:h2:mem:dtrack"); basicDataSource.setMaxActive(100);//from www. jav a2s . c o m return basicDataSource; }
From source file:org.paxml.tag.sql.SqlDataSourceTag.java
private DataSource getCacheOrCreate() { String key = getCacheKey();//ww w . j av a 2 s . c om DataSource ds = CACHE.get(key); if (ds == null) { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(getDriver()); dataSource.setUrl(url); dataSource.setUsername(username); dataSource.setPassword(password); dataSource.setDefaultAutoCommit(true); DataSource existing = CACHE.putIfAbsent(key, dataSource); if (existing != null) { ds = existing; } else { ds = dataSource; } } return ds; }