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

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

Introduction

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

Prototype

public synchronized void setDriverClassName(String driverClassName) 

Source Link

Document

Sets the jdbc driver class name.

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 . ja  v  a  2 s . c o  m

    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

/**
 * ?//from   w  w  w .  ja v  a  2 s . co  m
 */
@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: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 ww  .ja v  a  2  s .c om*/
}

From source file:com.edu.ufps.maregroups.util.Pool.java

private static void inicializarDataSource() {
    BasicDataSource dsBasico = new BasicDataSource();
    dsBasico.setDriverClassName(DB_DRIVER);
    dsBasico.setUsername(DB_USUARIO);/*from   w  ww  .  j  av  a 2s  .  c om*/
    dsBasico.setPassword(DB_CONTRASENA);
    dsBasico.setUrl(DB_URL);
    dsBasico.setMaxTotal(100);
    datasource = dsBasico;
}

From source file:gruposinvestigacion.model.util.Pool.java

private static void inicializarDataSource() {
    BasicDataSource dsBasico = new BasicDataSource();
    dsBasico.setDriverClassName(db_driver);
    dsBasico.setUsername(db_usuario);//ww  w . j av  a2s.c om
    dsBasico.setPassword(db_contrasena);
    dsBasico.setUrl(db_url);
    dsBasico.setMaxTotal(100);
    datasource = dsBasico;
}

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: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;/*w w  w .j a v  a2 s  .c o  m*/
}

From source file:BasicDataSourceExample.java

public static DataSource setupDataSource(String connectURI) {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("org.h2.Driver");
    ds.setUrl(connectURI);//from   ww  w  .ja v  a2s .c o  m
    return ds;
}

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:com.magnet.mmx.server.plugin.mmxmgmt.db.UnitTestDSProvider.java

/**
 * Get unit test datasource//from   ww w  .j  a  v a  2 s .  c om
 * @return
 */
public static BasicDataSource getDataSource() {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(dsConfig.getDriver());
    ds.setUsername(dsConfig.getUser());
    ds.setPassword(dsConfig.getPassword());
    ds.setUrl(dsConfig.getUrl());
    return ds;
}