Example usage for org.apache.commons.dbcp2 BasicDataSource setUrl

List of usage examples for org.apache.commons.dbcp2 BasicDataSource setUrl

Introduction

In this page you can find the example usage for org.apache.commons.dbcp2 BasicDataSource setUrl.

Prototype

public synchronized void setUrl(String url) 

Source Link

Document

Sets the #url .

Note: this method currently has no effect once the pool has been initialized.

Usage

From source file:com.magnet.mmx.util.DatabaseExport.java

public static void main(String[] args) throws Exception {
    InputStream inputStream = DeviceDAOImplTest.class.getResourceAsStream("/test.properties");

    Properties testProperties = new Properties();
    testProperties.load(inputStream);// ww w.  j a va  2  s .com

    String host = testProperties.getProperty("db.host");
    String port = testProperties.getProperty("db.port");
    String user = testProperties.getProperty("db.user");
    String password = testProperties.getProperty("db.password");
    String driver = testProperties.getProperty("db.driver");
    String schema = testProperties.getProperty("db.schema");

    String url = "jdbc:mysql://" + host + ":" + port + "/" + schema;

    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(driver);
    ds.setUsername(user);
    ds.setPassword(password);
    ds.setUrl(url);
    TreeMap<String, String> map = new TreeMap<String, String>();
    map.put("mmxTag", "SELECT * FROM mmxTag ");
    doWork(ds.getConnection(), map);
}

From source file:com.sinotopia.mybatis.plus.test.GlobalConfigurationTest.java

/**
 * ?// ww w  .j a  v a  2  s. com
 */
@SuppressWarnings("unchecked")
public static void main(String[] args) {
    GlobalConfiguration global = GlobalConfiguration.defaults();
    global.setAutoSetDbType(true);
    // FieldStrategy.Empty
    global.setFieldStrategy(2);
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/mybatis-plus?characterEncoding=UTF-8");
    dataSource.setUsername("root");
    dataSource.setPassword("521");
    dataSource.setMaxTotal(1000);
    GlobalConfiguration.setMetaData(dataSource, global);
    // ?
    InputStream inputStream = GlobalConfigurationTest.class.getClassLoader()
            .getResourceAsStream("mysql-config.xml");
    MybatisSessionFactoryBuilder factoryBuilder = new MybatisSessionFactoryBuilder();
    factoryBuilder.setGlobalConfig(global);
    SqlSessionFactory sessionFactory = factoryBuilder.build(inputStream);
    SqlSession session = sessionFactory.openSession(false);
    TestMapper testMapper = session.getMapper(TestMapper.class);
    /*Wrapper type = Condition.instance().eq("id",1).or().in("type", new Object[]{1, 2, 3, 4, 5, 6});
    List list = testMapper.selectList(type);
    System.out.println(list.toString());*/
    Test test = new Test();
    test.setCreateTime(new Date());
    // ?
    test.setType("");
    testMapper.insert(test);

    SqlSession sqlSession = sessionFactory.openSession(false);
    NotPKMapper pkMapper = sqlSession.getMapper(NotPKMapper.class);
    NotPK notPK = new NotPK();
    notPK.setUuid(UUID.randomUUID().toString());
    int num = pkMapper.insert(notPK);
    Assert.assertTrue(num > 0);
    NotPK notPK1 = pkMapper.selectOne(notPK);
    Assert.assertNotNull(notPK1);
    pkMapper.selectPage(RowBounds.DEFAULT, Condition.create().eq("type", 12121212));
    NotPK notPK2 = null;
    try {
        notPK2 = pkMapper.selectById("1");
    } catch (Exception e) {
        System.out.println(",");
    }
    Assert.assertNull(notPK2);
    int count = pkMapper.selectCount(Condition.EMPTY);
    Assert.assertTrue(count > 0);
    int deleteCount = pkMapper.delete(null);
    Assert.assertTrue(deleteCount > 0);
    session.rollback();
    sqlSession.commit();
}

From source file:agency.Agency.java

private static DataSource prepareDataSource() throws SQLException, IOException {
    Properties myconf = new Properties();
    myconf.load(Agency.class.getResourceAsStream("/myconf.properties"));

    BasicDataSource ds = new BasicDataSource();

    ds.setUrl(myconf.getProperty("jdbc.url"));
    ds.setUsername(myconf.getProperty("jdbc.user"));
    ds.setPassword(myconf.getProperty("jdbc.password"));

    return ds;/*from  w  w  w  .ja  v a2 s  .  co  m*/
}

From source file:br.com.ceosites.cachedproperties.cache.test.util.DatabaseUtils.java

public static DataSource prepareDatabase() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setUrl("jdbc:hsqldb:mem:dataSource?hsqldb.sqllog=3");
    dataSource.setUsername("SA");
    dataSource.setPassword("");
    dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
    ScriptRunner scriptRunner = new ScriptRunner(dataSource);

    try {/*  w  w  w.j  a  v  a2  s  .  c  om*/
        scriptRunner.execute(new BufferedReader(new FileReader("src/main/resources/db/create-db.sql")));
        scriptRunner.execute(new BufferedReader(new FileReader("src/main/resources/db/insert-data.sql")));
    } catch (IOException ex) {
        LOGGER.error("Error on read SQL files.", ex);
    } catch (SQLException ex) {
        LOGGER.error("Error on  execute SQL script.", ex);
    }

    return dataSource;
}

From source file:cz.muni.pv168.dragonrental.backend.DragonRental.java

public static DataSource createMemoryDatabase() {
    BasicDataSource bds = new BasicDataSource();
    //set JDBC driver and URL
    bds.setDriverClassName(EmbeddedDriver.class.getName());
    bds.setUrl("jdbc:derby:memory:peopleDB;create=true");
    //populate db with tables and data
    new ResourceDatabasePopulator(new ClassPathResource("schema-javadb.sql"),
            new ClassPathResource("test-data.sql")).execute(bds);
    return bds;//from w w w.j av a  2 s.co m
}

From source file:com.javacreed.examples.sql.DatabaseUtils.java

public static BasicDataSource createDataSource() {
    final BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/test_large_text");
    dataSource.setUsername("root");
    dataSource.setPassword("root");
    return dataSource;
}

From source file:BasicDataSourceExample.java

public static DataSource setupDataSource(String connectURI) {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("org.h2.Driver");
    ds.setUrl(connectURI);
    return ds;/*from  w w  w. j a va 2 s.c  o m*/
}

From source file:com.teradata.tempto.internal.query.JdbcUtils.java

private static DataSource createPoolingDataSource(JdbcConnectivityParamsState jdbcParamsState) {

    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(jdbcParamsState.driverClass);
    dataSource.setUrl(jdbcParamsState.url);
    dataSource.setUsername(jdbcParamsState.user);
    dataSource.setPassword(jdbcParamsState.password);
    dataSource.setDriverClassLoader(getDriverClassLoader(jdbcParamsState));
    return dataSource;
}

From source file:cz.muni.fi.pv168.project.hotelmanager.Main.java

public static DataSource createMemoryDatabase() {
    log.info("starts creation of tables");
    BasicDataSource bds = new BasicDataSource();
    //set JDBC driver and URL
    bds.setDriverClassName(EmbeddedDriver.class.getName());
    log.info("try create Datasource");
    bds.setUrl("jdbc:derby:memory:HotelManagerDB;create=true");
    //populate db with tables and data
    log.info("try create tables");
    new ResourceDatabasePopulator(new ClassPathResource("schema-javadb.sql")).execute(bds);
    log.info("return datasource");
    return bds;//from w w  w .jav  a 2s.  c o  m
}

From source file:common.DBHelper.java

public static DataSource getDataSource() {

    Properties prop = new Properties();

    try (InputStream input = DBHelper.class.getResourceAsStream("/config.PROPERTIES");) {
        prop.load(input);/*from  ww w.  j  a  v  a2s .  c  om*/
    } catch (IOException e) {
        logger.error("error reading properties", e);
    }

    BasicDataSource ds = new BasicDataSource();

    ds.setUrl(prop.getProperty("dbUrl"));
    ds.setDriverClassName("org.apache.derby.jdbc.ClientDriver");
    ds.setUsername(prop.getProperty("dbUsername"));
    ds.setPassword(prop.getProperty("dbPassword"));

    return ds;
}