List of usage examples for org.apache.commons.dbcp BasicDataSource BasicDataSource
BasicDataSource
From source file:com.dangdang.ddframe.rdb.sharding.config.common.api.ShardingRuleBuilderTest.java
@Test public void testMin() { Yaml yaml = new Yaml(new Constructor(ShardingRuleConfig.class)); Map<String, DataSource> dsMap = new HashMap<>(); dsMap.put("ds", new BasicDataSource()); ShardingRuleConfig config = (ShardingRuleConfig) yaml .load(ShardingRuleBuilderTest.class.getResourceAsStream("/config/config-min.yaml")); ShardingRule shardingRule = new ShardingRuleBuilder("config-min.yaml", dsMap, config).build(); assertThat(shardingRule.getTableRules().size(), is(1)); }
From source file:be.ugent.tiwi.sleroux.newsrec.stormNewsFetch.dao.mysqlImpl.JDBCRatingsDao.java
/** * * @throws RatingsDaoException/*from w w w. java 2 s .c om*/ */ public JDBCRatingsDao() throws RatingsDaoException { logger.debug("constructor called"); if (connectionPool == null) { try { logger.debug("creating connectionpool"); String driver = bundle.getString("dbDriver"); String user = bundle.getString("dbUser"); String pass = bundle.getString("dbPass"); String url = bundle.getString("dbUrl"); url = url + "?user=" + user + "&password=" + pass; connectionPool = new BasicDataSource(); connectionPool.setDriverClassName(driver); connectionPool.setUsername(user); connectionPool.setPassword(pass); connectionPool.setUrl(url); logger.debug("connectionpool created"); logger.debug("creating preparedstatements"); String statementText = bundle.getString("selectRatingsQuery"); Connection conn = connectionPool.getConnection(); conn.setAutoCommit(true); selectStatement = conn.prepareStatement(statementText); statementText = bundle.getString("insertUpdateRatingsQuery"); insertUpdateRatingStatement = conn.prepareStatement(statementText); logger.debug("created preparedstatements"); } catch (SQLException ex) { logger.error(ex.getMessage(), ex); throw new RatingsDaoException(ex); } } }
From source file:com.endegraaf.examples.app.DbHelper.java
public void init() { DbHelper.LOGGER.debug("Loading properties"); final Properties properties = new Properties(); try {// w w w. j ava 2 s . c om properties.load(getClass().getResourceAsStream("/app.properties")); } catch (final IOException e) { DbHelper.LOGGER.error("Failed to load the properties"); } DbHelper.LOGGER.debug("Creating the data source"); ds = new BasicDataSource(); ds.setDriverClassName(properties.getProperty("db.driver.className")); ds.setUrl("jdbc:" + properties.getProperty("db.driver") + "://" + properties.getProperty("db.host")); ds.setUsername(properties.getProperty("db.username")); ds.setPassword(properties.getProperty("db.password")); /* * H2 ds.setDriverClassName("org.h2.Driver"); * ds.setUrl("jdbc:h2:target/db"); ds.setUsername("sa"); * ds.setPassword(""); */ DbHelper.LOGGER.debug("Call the flyway object instance and set the datasource."); final Flyway flyway = new Flyway(); flyway.setDataSource(ds); //DbHelper.LOGGER.debug("Clean the database schema before migration."); //flyway.clean(); DbHelper.LOGGER.debug("Executing Flyway (database migration)"); flyway.migrate(); }
From source file:com.rohan.blog.blog.dataaccess.DbHelper.java
public void init() { DbHelper.LOGGER.debug("Loading properties"); final Properties properties = new Properties(); try {//from w w w. jav a2 s . c o m properties.load(getClass().getResourceAsStream("/app.properties")); } catch (final IOException e) { DbHelper.LOGGER.error("Failed to load the properties"); } DbHelper.LOGGER.debug("Creating the data source"); ds = new BasicDataSource(); ds.setDriverClassName(properties.getProperty("db.driver.className")); ds.setUrl("jdbc:" + properties.getProperty("db.driver") + "://" + properties.getProperty("db.host")); ds.setUsername(properties.getProperty("db.username")); ds.setPassword(properties.getProperty("db.password")); /* * H2 ds.setDriverClassName("org.h2.Driver"); * ds.setUrl("jdbc:h2:target/db"); ds.setUsername("sa"); * ds.setPassword(""); */ DbHelper.LOGGER.debug("Call the flyway object instance and set the datasource."); final Flyway flyway = new Flyway(); flyway.setDataSource(ds); //DbHelper.LOGGER.debug("Clean the database schema before migration."); flyway.clean(); DbHelper.LOGGER.debug("Executing Flyway (database migration)"); flyway.migrate(); }
From source file:au.com.jwatmuff.eventmanager.model.misc.SessionLockerTest.java
@Override protected void setUp() throws Exception { System.out.println("setup"); BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName("org.sqlite.JDBC"); ds.setUrl("jdbc:sqlite::memory:"); this.dataSource = ds; }
From source file:com.bt.aloha.testing.JdbcHelper.java
private DataSource buildDataSource(String driver, String url, String username, String password) throws Exception { log.debug(String.format("Building datasource %s, %s, %s, %s", driver, url, username, password)); BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(driver);/*from w ww . j a va2 s . c o m*/ ds.setUrl(url); ds.setUsername(username); ds.setPassword(password); return ds; }
From source file:genepi.db.mysql.MySqlConnector.java
@Override public void connect() throws SQLException { log.debug("Establishing connection to " + user + "@" + host + ":" + port); if (DbUtils.loadDriver("com.mysql.jdbc.Driver")) { try {//from w ww. j a v a 2s.c o m dataSource = new BasicDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl("jdbc:mysql://" + host + "/" + database + "?autoReconnect=true&allowMultiQueries=true&rewriteBatchedStatements=true"); dataSource.setUsername(user); dataSource.setPassword(password); dataSource.setMaxActive(10); dataSource.setMaxWait(10000); dataSource.setMaxIdle(10); dataSource.setDefaultAutoCommit(true); } catch (Exception e) { e.printStackTrace(); } } else { System.out.println("MySQL Driver class not found."); } }
From source file:com.alibaba.druid.pool.bonecp.TestPSCache.java
public void f_test_dbcp() throws Exception { BasicDataSource ds = new BasicDataSource(); ds.setUrl("jdbc:mock:test"); ds.setMaxIdle(10);//from ww w . j av a2s. c o m ds.setPoolPreparedStatements(true); ds.setMaxOpenPreparedStatements(10); for (int i = 0; i < 10; ++i) { f(ds, 5); System.out.println("--------------------------------------------"); } }
From source file:cz.muni.fi.pv168.dressroomAppGui.MainMenuFrame.java
public static DataSource prepareDataSource() throws SQLException { BasicDataSource dataSource = new BasicDataSource(); //dataSource.setUrl("jdbc:derby:memory:dressroom-gui;create=true"); dataSource.setUrl(/* ww w . j av a 2s .co m*/ java.util.ResourceBundle.getBundle("cz.muni.fi.pv168.dressroomappgui/settings").getString("url")); dataSource.setUsername( java.util.ResourceBundle.getBundle("cz.muni.fi.pv168.dressroomappgui/settings").getString("user")); dataSource.setPassword(java.util.ResourceBundle.getBundle("cz.muni.fi.pv168.dressroomappgui/settings") .getString("password")); return dataSource; }
From source file:com.github.viktornar.configuration.ApplicationConfig.java
@Profile("development") @Bean(destroyMethod = "close") public DataSource dataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("org.hsqldb.jdbcDriver"); dataSource.setUrl("jdbc:hsqldb:mem:composer_db"); dataSource.setUsername("sa"); dataSource.setPassword(""); return dataSource; }