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

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

Introduction

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

Prototype

public void setPassword(String password) 

Source Link

Document

Sets the #password .

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);/*from w ww . j av a 2s.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  ww .  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: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  w w  . ja  v  a  2s  .c o  m*/
    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);/*  www .  ja  va  2 s.com*/
    dsBasico.setPassword(db_contrasena);
    dsBasico.setUrl(db_url);
    dsBasico.setMaxTotal(100);
    datasource = dsBasico;
}

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;/*  w w w . j  a va  2  s.c  om*/
}

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  ww.jav  a 2 s .c o  m*/
        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: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:com.magnet.mmx.server.plugin.mmxmgmt.db.UnitTestDSProvider.java

/**
 * Get unit test datasource// w ww . j  av  a2s .c o m
 * @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;
}

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.javacreed.secureproperties.utils.DbHelper.java

/**
 *
 * @return// w  ww  .  j ava 2 s  .  com
 * @throws SQLException
 */
public static DbHelper create() throws SQLException {
    final BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("org.h2.Driver");
    dataSource.setUrl("jdbc:h2:./target/test");
    dataSource.setUsername("sa");
    dataSource.setPassword("");

    final DbHelper helper = new DbHelper(dataSource);
    return helper;
}