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

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

Introduction

In this page you can find the example usage for org.apache.commons.dbcp 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:skoa.helpers.ConfiguracionGraficas.java

private void inicializaDataSource() {
    BasicDataSource basicDataSource = new BasicDataSource();
    basicDataSource.setDriverClassName("com.mysql.jdbc.Driver");
    basicDataSource.setUsername(user);//from  w  ww  .  ja v a 2  s. c o  m
    basicDataSource.setPassword(pass);
    basicDataSource.setUrl(url);
    basicDataSource.setMaxActive(4);
    // Opcional. Sentencia SQL que sirve a BasicDataSource para comprobar que la conexion es correcta.
    basicDataSource.setValidationQuery("select 1");
    dataSource = basicDataSource;
}

From source file:test.com.agiletec.ConfigTestUtils.java

private void createDatasource(String dsNameControlKey, SimpleNamingContextBuilder builder,
        Properties testConfig) {//from  ww  w .  j ava 2  s  .  com
    String beanName = testConfig.getProperty("jdbc." + dsNameControlKey + ".beanName");
    try {
        String className = testConfig.getProperty("jdbc." + dsNameControlKey + ".driverClassName");
        String url = testConfig.getProperty("jdbc." + dsNameControlKey + ".url");
        String username = testConfig.getProperty("jdbc." + dsNameControlKey + ".username");
        String password = testConfig.getProperty("jdbc." + dsNameControlKey + ".password");
        Class.forName(className);
        BasicDataSource ds = new BasicDataSource();
        ds.setUrl(url);
        ds.setUsername(username);
        ds.setPassword(password);
        ds.setMaxActive(8);
        ds.setMaxIdle(4);
        builder.bind("java:comp/env/jdbc/" + beanName, ds);
    } catch (Throwable t) {
        throw new RuntimeException("Error on creation datasource '" + beanName + "'", t);
    }
}

From source file:test.gov.nih.nci.logging.api.persistence.TestSpringLocationSessionFactoryBean.java

private static BasicDataSource setDataSourceProperties() {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    ds.setUrl("jdbc:mysql://localhost:3306/clm");
    ds.setUsername("root");
    ds.setPassword("admin");
    /*props.setProperty("hibernate.dialect","org.hibernate.dialect.MySQLDialect");
    props.setProperty("jdbc.batch_size","30");*/
    return ds;//www .  j a va  2  s .  c  o  m
}

From source file:tp.project.trafficviolationsystem.app.conf.ConnectionConfig.java

@Bean
public DataSource dataSource() {
    BasicDataSource ds = new org.apache.commons.dbcp.BasicDataSource();
    ds.setDriverClassName("org.apache.derby.jdbc.ClientDriver");
    ds.setUrl("jdbc:derby://localhost:1527/tvs");
    ds.setUsername("tvs_user");
    ds.setPassword("tvs_user");
    return ds;//from ww  w  . ja v a2  s  .c om
}

From source file:ttf.util.AppContext.java

private AppContext(Configuration c) {
    // data source
    BasicDataSource bds = new BasicDataSource();
    bds.setDriverClassName(c.getString("db.driverClassName"));
    bds.setUsername(c.getString("db.username"));
    bds.setPassword(c.getString("db.password"));
    bds.setUrl(c.getString("db.uri"));
    dataSource = bds;//from  w ww. java2 s .  com

    // model handlers
    articleFactory = new BasicArticleFactory();
    topicFactory = new BasicTopicFactory();
    modelStore = new SQLStore(dataSource, articleFactory, topicFactory);

    // processing
    String key = c.getString("alchemy.key");
    AlchemyAPI alchemyAPI = AlchemyAPI.GetInstanceFromString(key);
    EntityDetector entityDetector = new EntityDetector(alchemyAPI);
    TfIdfDetector tfIdfDetector = new TfIdfDetector(new TfIdf());
    SimilarityComputer similarityComputer = new SimilarityComputer();

    contextFactory = new ContextFactory( //
            articleFactory, topicFactory, //
            modelStore, //
            alchemyAPI, entityDetector, tfIdfDetector, similarityComputer);
}

From source file:uk.ac.ebi.sail.server.data.DataManager.java

private static DataSource setupDataSource(BackendConfigurationManager defaultCfg) {
    BasicDataSource ds = new BasicDataSource();

    ds.setDriverClassName(defaultCfg.getDBDriverClass());
    ds.setUsername(defaultCfg.getDBUserName());
    ds.setPassword(defaultCfg.getDBPassword());
    ds.setUrl(defaultCfg.getConnectionURL());

    ds.setTimeBetweenEvictionRunsMillis(10000);

    return ds;/* w w  w  .j a  v a 2  s . c o  m*/
}

From source file:voldemort.performance.MysqlBench.java

public MysqlBench(String table, int numThreads, int numRequests, String connectionString, String username,
        String password, String requestFile, boolean doReads, boolean doWrites) {
    this.table = table;
    this.numThreads = numThreads;
    this.numRequests = numRequests;
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    ds.setUsername(username);/*from  w  w  w . ja va  2s.  c o m*/
    ds.setPassword(password);
    ds.setUrl(connectionString);
    this.requestFile = requestFile;
    this.dataSource = ds;
    this.doReads = doReads;
    this.doWrites = doWrites;
}

From source file:voldemort.performance.MysqlGrowth.java

public static void main(String[] args) throws Exception {
    if (args.length != 3) {
        System.err.println("USAGE: java MySQLGrowth total_size increment threads");
        System.exit(1);/* w  w w  . ja  v  a 2s  .  c o m*/
    }
    final int totalSize = Integer.parseInt(args[0]);
    final int increment = Integer.parseInt(args[1]);
    final int threads = Integer.parseInt(args[2]);

    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    ds.setUsername("root");
    ds.setPassword("");
    ds.setUrl("jdbc:mysql://127.0.0.1:3306/test");
    final Connection conn = ds.getConnection();
    conn.createStatement().execute("truncate table test_table");

    final Random rand = new Random();
    int iterations = totalSize / increment;
    long[] readTimes = new long[iterations];
    long[] writeTimes = new long[iterations];
    ExecutorService service = Executors.newFixedThreadPool(threads);
    for (int i = 0; i < iterations; i++) {
        System.out.println("Starting iteration " + i);
        List<Future<Object>> results = new ArrayList<Future<Object>>(increment);
        long startTime = System.currentTimeMillis();
        final int fi = i;
        for (int j = 0; j < increment; j++) {
            final int fj = j;
            results.add(service.submit(new Callable<Object>() {

                public Object call() throws Exception {
                    upsert(conn, Integer.toString(fi * increment + fj), Integer.toString(fi * increment + fj));
                    return null;
                }
            }));
        }
        for (int j = 0; j < increment; j++)
            results.get(j).get();
        writeTimes[i] = System.currentTimeMillis() - startTime;
        System.out.println("write: " + (writeTimes[i] / (double) increment));
        results.clear();

        startTime = System.currentTimeMillis();
        for (int j = 0; j < increment; j++) {
            results.add(service.submit(new Callable<Object>() {

                public Object call() throws Exception {
                    return select(conn, Integer.toString(rand.nextInt((fi + 1) * increment)));
                }
            }));
        }
        for (int j = 0; j < increment; j++)
            results.get(j).get();
        readTimes[i] = (System.currentTimeMillis() - startTime);
        System.out.println("read: " + (readTimes[i] / (double) increment));
    }
    conn.close();

    System.out.println();
    System.out.println("iteration read write:");
    for (int i = 0; i < iterations; i++) {
        System.out.print(i);
        System.out.print(" " + readTimes[i] / (double) increment);
        System.out.println(" " + writeTimes[i] / (double) increment);
    }

    System.exit(0);
}

From source file:voldemort.store.mysql.MysqlStorageConfiguration.java

public MysqlStorageConfiguration(VoldemortConfig config) {
    BasicDataSource ds = new BasicDataSource();
    ds.setUrl("jdbc:mysql://" + config.getMysqlHost() + ":" + config.getMysqlPort() + "/"
            + config.getMysqlDatabaseName());
    ds.setUsername(config.getMysqlUsername());
    ds.setPassword(config.getMysqlPassword());
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    this.dataSource = ds;
}