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.gvsig.fmap.dal.store.postgresql.PostgreSQLResource.java
protected DataSource createDataSource() { PostgreSQLResourceParameters jdbcParams = (PostgreSQLResourceParameters) this.getParameters(); BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(jdbcParams.getJDBCDriverClassName()); dataSource.setUsername(jdbcParams.getUser()); dataSource.setPassword(jdbcParams.getPassword()); dataSource.setUrl(jdbcParams.getUrl()); dataSource.setMaxWait(60L * 1000); // FIXME // FIXME Set Pool parameters: /*//from w ww . j av a 2 s . c o m dataSource.setMaxActive(maxActive); dataSource.setMaxIdle(maxActive); dataSource.setMaxOpenPreparedStatements(maxActive); dataSource.setMaxWait(maxActive); dataSource.setInitialSize(initialSize); dataSource.setDefaultReadOnly(defaultReadOnly); dataSource.setDefaultTransactionIsolation(defaultTransactionIsolation); dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); dataSource.setMinIdle(minIdle); dataSource.setTestOnBorrow(testOnBorrow); dataSource.setTestOnReturn(testOnReturn); dataSource.setTestWhileIdle(testOnReturn); dataSource .setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); dataSource.setAccessToUnderlyingConnectionAllowed(allow); dataSource.setLoginTimeout(seconds); dataSource.setLogWriter(out); */ return dataSource; }
From source file:org.hibernate.spatial.testing.DataSourceUtils.java
private void createBasicDataSource() { BasicDataSource bds = new BasicDataSource(); bds.setDriverClassName(jdbcDriver);/* w ww . j av a 2 s . c o m*/ bds.setUrl(jdbcUrl); bds.setUsername(jdbcUser); bds.setPassword(jdbcPass); dataSource = bds; }
From source file:org.jfaster.mango.support.DataSourceConfig.java
public static DataSource getDataSource(int i) { String driverClassName = getDriverClassName(i); String url = getUrl(i);/*from w ww. ja v a2 s. co m*/ String username = getUsername(i); String password = getPassword(i); BasicDataSource ds = new BasicDataSource(); ds.setUrl(url); ds.setUsername(username); ds.setPassword(password); ds.setInitialSize(1); ds.setMaxActive(1); ds.setDriverClassName(driverClassName); return ds; }
From source file:org.jooq.example.spark.SparkCRUD.java
public static void main(String[] args) throws Exception { final BasicDataSource ds = new BasicDataSource(); final Properties properties = new Properties(); properties.load(SparkCRUD.class.getResourceAsStream("/config.properties")); ds.setDriverClassName(properties.getProperty("db.driver")); ds.setUrl(properties.getProperty("db.url")); ds.setUsername(properties.getProperty("db.username")); ds.setPassword(properties.getProperty("db.password")); final DSLContext ctx = DSL.using(ds, SQLDialect.H2); // Creates a new book resource, will return the ID to the created resource // author and title are sent as query parameters e.g. /books?author=Foo&title=Bar post("/books", (request, response) -> { AuthorRecord author = upsertAuthor(ctx, request); BookRecord book = ctx.newRecord(BOOK); book.setAuthorId(author.getId()); book.setTitle(request.queryParams("title")); book.store();/*from w w w . j ava2 s . c om*/ response.status(201); // 201 Created return book.getId(); }); // Gets the book resource for the provided id get("/books/:id", (request, response) -> { Record2<String, String> book = ctx.select(BOOK.TITLE, AUTHOR.NAME).from(BOOK).join(AUTHOR) .on(BOOK.AUTHOR_ID.eq(AUTHOR.ID)) .where(BOOK.ID.eq(BOOK.ID.getDataType().convert(request.params(":id")))).fetchOne(); if (book != null) { return "Title: " + book.value1() + ", Author: " + book.value2(); } else { response.status(404); // 404 Not found return "Book not found"; } }); // Updates the book resource for the provided id with new information // author and title are sent as query parameters e.g. /books/<id>?author=Foo&title=Bar put("/books/:id", (request, response) -> { BookRecord book = ctx.selectFrom(BOOK) .where(BOOK.ID.eq(BOOK.ID.getDataType().convert(request.params(":id")))).fetchOne(); if (book != null) { AuthorRecord author = upsertAuthor(ctx, request); String newAuthor = request.queryParams("author"); String newTitle = request.queryParams("title"); if (newAuthor != null) { book.setAuthorId(author.getId()); } if (newTitle != null) { book.setTitle(newTitle); } book.update(); return "Book with id '" + book.getId() + "' updated"; } else { response.status(404); // 404 Not found return "Book not found"; } }); // Deletes the book resource for the provided id delete("/books/:id", (request, response) -> { BookRecord book = ctx.deleteFrom(BOOK) .where(BOOK.ID.eq(BOOK.ID.getDataType().convert(request.params(":id")))).returning().fetchOne(); if (book != null) { return "Book with id '" + book.getId() + "' deleted"; } else { response.status(404); // 404 Not found return "Book not found"; } }); // Gets all available book resources (id's) get("/books", (request, response) -> { return ctx.select(BOOK.ID).from(BOOK).fetch(BOOK.ID).stream().map(Object::toString) .collect(Collectors.joining(" ")); }); }
From source file:org.jxstar.dao.pool.PooledConnection.java
/** * ???//from www .j a va 2 s . c o m * @param dsName * @return */ private DataSource createSelfDataSource(DataSourceConfig dsConfig) { String dsName = dsConfig.getDataSourceName(); BasicDataSource ds = (BasicDataSource) _myDataSourceMap.get(dsName); if (ds != null) return ds; ds = new BasicDataSource(); //??? int iTranLevel = getTranLevelConstant(dsConfig.getTranLevel()); int maxnum = Integer.parseInt(dsConfig.getMaxConNum()); ds.setDriverClassName(dsConfig.getDriverClass()); ds.setUrl(dsConfig.getJdbcUrl()); ds.setUsername(dsConfig.getUserName()); ds.setPassword(dsConfig.getPassWord()); ds.setMaxIdle(maxnum); ds.setMaxActive(maxnum); ds.setMaxWait(Long.parseLong(dsConfig.getMaxWaitTime())); ds.setDefaultAutoCommit(false); ds.setDefaultTransactionIsolation(iTranLevel); //????SystemVarserver.xml? String validTest = dsConfig.getValidTest(); String validQuery = dsConfig.getValidQuery(); if (validTest.equalsIgnoreCase("true") && validQuery.length() > 0) { _log.showDebug("pool test use query..."); ds.setTestOnBorrow(true); ds.setValidationQuery(validQuery); ds.setValidationQueryTimeout(3); } //?mysql??? //????? if (dsConfig.getValidIdle().equalsIgnoreCase("true")) { _log.showDebug("pool idle valid thread started..."); ds.setMinIdle(5); ds.setTestWhileIdle(true); //1030?5 ds.setMinEvictableIdleTimeMillis(30 * 60 * 1000);//30 minus ds.setTimeBetweenEvictionRunsMillis(10 * 60 * 1000);//10 minus } //??? _myDataSourceMap.put(dsName, ds); return ds; }
From source file:org.kaaproject.kaa.server.datamigration.utils.DataSources.java
/** * Create data source based on passed options. * * @param opt options that used to build data source * @return the data source//w ww . java2 s .c om */ public static DataSource getDataSource(Options opt) { BasicDataSource bds = new BasicDataSource(); bds.setDriverClassName(opt.getDriverClassName()); bds.setUrl(opt.getJdbcUrl()); bds.setUsername(opt.getUsername()); bds.setPassword(opt.getPassword()); bds.setDefaultAutoCommit(false); return bds; }
From source file:org.karsha.lucene.jdbc.JDBCDatabaseUtil.java
/** * Gets the data source./*from w w w .j a va 2 s . c o m*/ * * @return the data source */ public synchronized static DataSource getDataSource() { // String url = "jdbc:mysql://rss1.stratoslive.wso2.com/karsha_annotate_karsha_opensource_lk"; // String username = "adm_ann_lQrhzZUK"; // String password = "admin@lsf"; //MysqlDataSource dataSource = new MysqlDataSource(); BasicDataSource dataSource = new BasicDataSource(); // dataSource.setUser("adm_ann_lQrhzZUK"); // dataSource.setPassword("admin@lsf"); // dataSource.setUrl("jdbc:mysql://rss1.stratoslive.wso2.com/karsha_annotate_karsha_opensource_lk"); dataSource.setUsername("admin_i+APQovg"); dataSource.setPassword("admin"); //emulateLocators=true&useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false dataSource.setUrl( "jdbc:mysql://rss1.stratoslive.wso2.com/karshaindex_kasunperera_com?emulateLocators=true&useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false"); // dataSource.setUsername("root"); // dataSource.setPassword("nbuser"); // dataSource.setUrl("jdbc:mysql://localhost:3306/karshaindex?emulateLocators=true&useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false"); // dataSource.setEmulateLocators(true); return dataSource; }
From source file:org.kiy0taka.dbunit.DbUnitRunner.java
protected DataSource createDataSource() { BasicDataSource result = new BasicDataSource(); result.setUsername(username);//from ww w . j a va 2s . c om result.setPassword(password); result.setUrl(jdbcUrl); return result; }
From source file:org.lucane.server.database.DatabaseAbstractionLayer.java
/** * DatabaseLayer Factory// ww w . ja v a 2 s.c om * Get the layer corresponding to the driver */ public static DatabaseAbstractionLayer createLayer(ServerConfig config) throws Exception { Class.forName(config.getDbDriver()); BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(config.getDbDriver()); ds.setUsername(config.getDbLogin()); ds.setPassword(config.getDbPassword()); ds.setUrl(config.getDbUrl()); ds.setPoolPreparedStatements(true); ds.setInitialSize(config.getDbPoolInitialSize()); ds.setMaxActive(config.getDbPoolMaxActive()); ds.setMaxIdle(config.getDbPoolMaxIdle()); ds.setMinIdle(config.getDbPoolMinIdle()); ds.setMaxWait(config.getDbPoolMaxWait()); Logging.getLogger() .info("Pool initialized (" + "initial size=" + config.getDbPoolInitialSize() + ", max active=" + config.getDbPoolMaxActive() + ", max idle=" + config.getDbPoolMaxIdle() + ", min idle=" + config.getDbPoolMinIdle() + ", max wait=" + config.getDbPoolMaxWait() + ")"); //-- dynamic layer loading Class klass = Class.forName(config.getDbLayer()); Class[] types = { DataSource.class }; Object[] values = { ds }; Constructor constr = klass.getConstructor(types); return (DatabaseAbstractionLayer) constr.newInstance(values); }
From source file:org.midao.jdbc.core.pool.MjdbcPoolBinder.java
/** * Returns new Pooled {@link DataSource} implementation * * In case this function won't work - use {@link #createDataSource(java.util.Properties)} * * @param url Database connection url/*from www . ja va2 s . c o m*/ * @param userName Database user name * @param password Database user password * @return new Pooled {@link DataSource} implementation * @throws SQLException */ public static DataSource createDataSource(String url, String userName, String password) throws SQLException { assertNotNull(url); assertNotNull(userName); assertNotNull(password); BasicDataSource ds = new BasicDataSource(); ds.setUrl(url); ds.setUsername(userName); ds.setPassword(password); return ds; }