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:rzd.vivc.documentexamination.configuration.SpringDateConfigMySQL.java

@Bean
//? ? /*  w w w .ja  v a 2s.  c  o m*/
public DataSource dataSource() {
    //MySQL
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    //? 
    ds.setUrl("jdbc:mysql://localhost:3306/dateexamination");
    ds.setUsername("root");
    /* ds.setUsername("exam");
    ds.setPassword("exam68");*/
    //
    ds.setInitialSize(5);
    ds.setMaxIdle(5);
    ds.setMaxTotal(15);

    return ds;
}

From source file:tilda.db.ConnectionPool.java

public static void init(String Id, String Driver, String DB, String User, String Pswd, int InitialSize,
        int MaxSize) {
    if (_DataSourcesById.get(Id) == null)
        synchronized (_DataSourcesById) {
            if (_DataSourcesById.get(Id) == null) // Definitely no connection pool by that name
            {/*from   ww w  . j a v  a  2  s.co m*/
                String Sig = DB + "``" + User;
                BasicDataSource BDS = _DataSourcesBySig.get(Sig); // Let's see if that DB definition is already there
                if (BDS == null) {
                    LOG.info("Initializing a fresh pool for Id=" + Id + ", DB=" + DB + ", User=" + User
                            + ", and Pswd=Shhhhhhh!");
                    BDS = new BasicDataSource();
                    BDS.setDriverClassName(Driver);
                    BDS.setUrl(DB);
                    if (TextUtil.isNullOrEmpty(Pswd) == false && TextUtil.isNullOrEmpty(User) == false) {
                        BDS.setUsername(User);
                        BDS.setPassword(Pswd);
                    }
                    BDS.setInitialSize(InitialSize);
                    BDS.setMaxTotal(MaxSize);
                    BDS.setDefaultAutoCommit(false);
                    BDS.setDefaultTransactionIsolation(java.sql.Connection.TRANSACTION_READ_COMMITTED);
                    BDS.setDefaultQueryTimeout(20000);
                    _DataSourcesBySig.put(Sig, BDS);
                } else {
                    LOG.info("Merging pool with ID " + Id + " into prexisting pool " + Sig);
                    if (BDS.getInitialSize() < InitialSize)
                        BDS.setInitialSize(InitialSize);
                    if (BDS.getMaxTotal() < MaxSize)
                        BDS.setMaxTotal(MaxSize);

                }
                _DataSourcesById.put(Id, BDS);
            }
        }
}

From source file:uk.co.platosys.db.jdbc.ConnectionBroker.java

private void init() {

    List<DatabaseCredentials> databases = properties.getDatabases();
    for (DatabaseCredentials credentials : databases) {

        String name = "";
        String driver = "";
        String userName = "";
        String password = "";
        String url = "";
        try {// w  w  w  .  j  a v a 2  s  . c o  m
            name = credentials.getName();
            logger.log("ConnectionBroker initialising database " + name);
            driver = credentials.getDriver();
            url = credentials.getUrl();
            userName = credentials.getUsername();
            password = credentials.getPassword();
            logger.log("ConnectionBroker credentials for " + name + " are " + driver + " " + url + " "
                    + userName + " " + password);

        } catch (Exception e) {
            logger.log("ConnectionBroker had a problem getting credentials for " + name, e);
        }
        /* try{
            //although we only use postgresql, there's no reason we couldn't use a different sql rdbms with a different driver for each
            //database.
        Class.forName(driver);
         }catch(ClassNotFoundException e){
        logger.log("ConnectionBroker couldn't load database driver", e);
         }*/
        try {
            /*connFac = new DriverManagerConnectionFactory(url, userName, password);
            PoolableConnectionFactory poolableConFac = new PoolableConnectionFactory(connFac, null);
            GenericObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<PoolableConnection>(poolableConFac);
            pools.put(name, connectionPool);
            poolableConFac.setPool(connectionPool);
            PoolingDataSource<PoolableConnection> dataSource = new PoolingDataSource<PoolableConnection>(connectionPool);*/
            BasicDataSource dataSource = new BasicDataSource();
            dataSource.setDriverClassName(driver);
            dataSource.setUsername(userName);
            dataSource.setPassword(password);
            dataSource.setUrl(url);
            dataSource.setMinIdle(2);
            dataSource.setMaxTotal(MAX_ACTIVE);
            logger.log(5, "ConnectionBroker has made BasicDataSource " + dataSource.toString());
            logger.log("Datasource " + name + " has " + dataSource.getMaxTotal() + " maxConnections");
            try {
                Connection connection = dataSource.getConnection();
                connection.close();
                dataSources.put(name, dataSource);
                dataSet.add(dataSource);
                logger.log(5, "ConnectionBroker has initialised database " + name);
            } catch (PSQLException psqe) {
                logger.log("could not make a test connection to database: " + name, psqe);
            }
        } catch (Exception e) {
            logger.log("ConnectionBroker had a problem configuring the pool with " + name, e);
        }
    }
    done = true;
}

From source file:uk.org.linuxgrotto.config.JpaConfiguration.java

@Bean
public DataSource dataSource() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(environment.getProperty("jdbc.driverClassName"));
    dataSource.setUrl(environment.getProperty("jdbc.url"));
    dataSource.setUsername(environment.getProperty("jdbc.username"));
    dataSource.setPassword(environment.getProperty("jdbc.password"));

    return dataSource;
}

From source file:ws.rocket.sqlstore.test.SqlStoreTest.java

@BeforeClass
public void setUp() throws SQLException, IOException {
    ResourceBundle bundle = ResourceBundle.getBundle("ws.rocket.sqlstore.test.test");

    File dbPath = new File(bundle.getString("jdbc.dbPath"));
    if (!dbPath.exists()) {
        dbPath.mkdirs();/*from  www  .  j  ava  2  s  .  com*/
    }

    System.setProperty("derby.system.home", dbPath.getCanonicalPath());

    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(bundle.getString("jdbc.driver"));
    ds.setUrl(bundle.getString("jdbc.url"));
    ds.setDefaultReadOnly(true);
    ds.setDefaultAutoCommit(false);
    ds.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
    ds.setInitialSize(Integer.parseInt(bundle.getString("jdbc.initialConnections")));

    this.dataSource = ds;

    boolean tableExists;
    try (Connection c = this.dataSource.getConnection()) {
        DatabaseMetaData meta = c.getMetaData();
        try (ResultSet rs = meta.getTables(null, "SQLSTORE", "PERSON", new String[] { "TABLE" })) {
            tableExists = rs.next();
        }
    }

    if (tableExists) {
        dropTables();
    }
}

From source file:xml.cz.Parser.java

/**
 * Main class in which all data are parsed
 * @param args arguments on main class - not supported
 * @throws IOException/*from  w ww . ja va2  s.  c  o  m*/
 * @throws SQLException
 * @throws SAXException
 * @throws ParserConfigurationException 
 */
public static void main(String[] args)
        throws IOException, SQLException, SAXException, ParserConfigurationException {
    Properties pro = new Properties();
    pro.load(new FileInputStream("src/main/java/configuration/jdbc.properties"));

    BasicDataSource ds = new BasicDataSource();
    ds.setUrl(pro.getProperty("url"));
    ds.setUsername(pro.getProperty("username"));
    ds.setPassword(pro.getProperty("password"));

    SectorManagerImpl sectorManager = new SectorManagerImpl();
    sectorManager.setDataSource(ds);
    ClassificationManagerImpl classificationManager = new ClassificationManagerImpl();
    classificationManager.setDataSource(ds);
    RegionManagerImpl regionManager = new RegionManagerImpl();
    regionManager.setDataSource(ds);

    Parser parser = new Parser();
    parser.parseSector(sectorManager);
    parser.parseClassification(classificationManager);
    parser.parseRegion(regionManager);

    ds.close();
}

From source file:xml.sk.Parser.java

public static void main(String[] args) throws IOException, SQLException, ParserConfigurationException,
        SAXException, XPathExpressionException, ParseException {
    Properties pro = new Properties();
    pro.load(new FileInputStream("src/main/java/configuration/jdbc.properties"));

    BasicDataSource ds = new BasicDataSource();
    ds.setUrl(pro.getProperty("url"));
    ds.setUsername(pro.getProperty("username"));
    ds.setPassword(pro.getProperty("password"));

    SectorManagerImpl sectorManager = new SectorManagerImpl();
    sectorManager.setDataSource(ds);/*from   w w  w .j  ava 2s  .c  o  m*/
    ClassificationManagerImpl classificationManager = new ClassificationManagerImpl();
    classificationManager.setDataSource(ds);
    EducationManagerImpl educationManager = new EducationManagerImpl();
    educationManager.setDataSource(ds);
    AgeManagerImpl ageManager = new AgeManagerImpl();
    ageManager.setDataSource(ds);

    Parser parser = new Parser();
    parser.parseSectorSk(sectorManager);
    parser.parseClassificationSk(classificationManager);
    parser.parseEducationSk(educationManager);
    parser.parseAgeSk(ageManager);

    ds.close();
}