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

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

Introduction

In this page you can find the example usage for org.apache.commons.dbcp 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:nl.surfnet.coin.db.MigrationsTest.java

private BasicDataSource hsqldbDataSource() {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("org.hsqldb.jdbcDriver");
    ds.setUrl("jdbc:hsqldb:mem:api");
    ds.setUsername("sa");
    ds.setPassword("");
    return ds;/*  w  w  w.  j  av a 2 s  . c o  m*/
}

From source file:nl.surfnet.coin.db.MigrationsTest.java

private BasicDataSource mysqlDataSource() {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    ds.setUrl("jdbc:mysql://localhost:3306/apitest");
    ds.setUsername("root");
    ds.setPassword("");
    return ds;//from ww w  . ja va  2s. c om
}

From source file:nl.trivento.albero.repositories.DatabaseRepository.java

private DataSource createBasicDataSource(Map<String, String> parameters) throws ConfigurationException {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(parameters.get(DRIVER));
    dataSource.setUrl(parameters.get(URL));
    dataSource.setUsername(parameters.get(USER));
    dataSource.setPassword(parameters.get(PASSWORD));

    return dataSource;
}

From source file:org.activiti.spring.test.jpa.JPASpringTest.java

@Bean
public DataSource dataSource() {
    BasicDataSource basicDataSource = new BasicDataSource();
    basicDataSource.setUsername("sa");
    basicDataSource.setUrl("jdbc:h2:mem:activiti");
    basicDataSource.setDefaultAutoCommit(false);
    basicDataSource.setDriverClassName(org.h2.Driver.class.getName());
    basicDataSource.setPassword("");
    return basicDataSource;
}

From source file:org.alexlg.bankit.Launcher.java

public static void main(String[] args) throws Exception {
    LoadingFrame loadingFrame = new LoadingFrame();
    loadingFrame.display();//from   w ww. j  a  va  2  s  .c o m

    File warFile = null;
    if (!(args.length > 0 && args[0].equals("nowar"))) { //can be deactivated for tests
        //searching war file in lib dir
        File libDir = new File("lib");
        if (!libDir.isDirectory())
            throw new Exception("Directory [lib] doesn't exists in [" + libDir.getAbsolutePath() + "]");

        for (File file : libDir.listFiles()) {
            if (file.getName().endsWith(".war")) {
                warFile = file;
                break;
            }
        }
        if (warFile == null)
            throw new Exception("Cant find any .war file in [" + libDir.getAbsolutePath() + "]");
    }

    final int port = findAvailablePort(8080);

    //server definition
    Server server = new Server();
    server.setGracefulShutdown(1000);
    server.setStopAtShutdown(true);

    //http connector
    Connector connector = new SelectChannelConnector();
    connector.setHost("localhost");
    connector.setPort(port);
    server.addConnector(connector);

    //handlers context
    ContextHandlerCollection contexts = new ContextHandlerCollection();

    //shutdown servlet
    ServletContextHandler shutdownServletCtx = new ServletContextHandler();
    shutdownServletCtx.setContextPath("/shutdown");
    shutdownServletCtx.addServlet(new ServletHolder(new ShutdownServlet(server)), "/*");
    contexts.addHandler(shutdownServletCtx);

    //bankit war
    if (warFile != null) {
        WebAppContext webAppContext = new WebAppContext();
        webAppContext.setContextPath("/bankit");
        webAppContext.setWar(warFile.getAbsolutePath());
        webAppContext.setTempDirectory(new File("tmp/"));

        //prevent slf4j api to be loaded by the webapp
        //in order to keep the jetty logback configuration
        webAppContext.setClassLoader(new WebAppClassLoaderNoSlf4J(webAppContext));

        contexts.addHandler(webAppContext);
    }

    //database datasource
    BasicDataSource datasource = new BasicDataSource();
    datasource.setDriverClassName("org.h2.Driver");
    datasource.setUrl("jdbc:h2:bankit");
    new Resource("jdbc/bankit", datasource);

    //standalone jndi resource
    Boolean standalone = true;
    new Resource("java:comp/env/standalone", standalone);

    //adding Handlers for servlet and war
    server.setHandler(contexts);
    server.start();

    //start the user browser after the server started
    startBrowser("http://localhost:" + port + "/bankit/");
    loadingFrame.close();

    server.join();
}

From source file:org.ambraproject.doi.BaseResolverTest.java

@BeforeClass
public void createDB() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
    dataSource.setUrl("jdbc:hsqldb:mem:testdb");
    dataSource.setUsername("sa");
    dataSource.setPassword("");
    this.dataSource = dataSource;
    jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.execute("drop table if exists annotation;" + "drop table if exists article;"
            + "create table article (" + "  articleID bigint not null," + "  doi varchar(255) not null,"
            + "  primary key (articleID)" + ");" + "create table annotation ("
            + "  annotationID bigint not null," + "  annotationURI varchar(255) not null,"
            + "  articleID bigint null," + "  type varchar(16) default null," + "  primary key (annotationID)"
            + ");" + "alter table annotation add foreign key (articleID) references article (articleID);");
}

From source file:org.ambraproject.rhino.config.TestConfiguration.java

@Bean
public DataSource dataSource() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setUrl("jdbc:hsqldb:mem:testdb");
    dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
    return dataSource;
}

From source file:org.apache.airavata.common.utils.DBUtil.java

/**
 * Gets a new DBCP data source./*w w  w  . j  ava 2  s. c  o  m*/
 * 
 * @return A new data source.
 */
public DataSource getDataSource() {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(this.driverName);
    ds.setUsername(this.databaseUserName);
    ds.setPassword(this.databasePassword);
    ds.setUrl(this.jdbcUrl);

    return ds;
}

From source file:org.apache.drill.exec.store.http.InsertTestData.java

public static DataSource createDataSource(String driver, String url, String userName, String password) {

    BasicDataSource source = new BasicDataSource();
    source.setDriverClassName(driver);
    source.setUrl(url);//from w  w w.  j  a v  a  2s  . c  o  m

    if (userName != null) {
        source.setUsername(userName);
    }

    if (password != null) {
        source.setPassword(password);
    }
    source.setInitialSize(1);
    source.setPoolPreparedStatements(true);
    try {
        // initial a connection
        source.getConnection();
    } catch (SQLException sqlE) {

        logger.error("db connection error: ", sqlE);
    }
    return source;

}

From source file:org.apache.drill.exec.store.http.util.DBUtil.java

public static DataSource createDataSource(String driver, String url, String userName, String password) {

    BasicDataSource source = new BasicDataSource();
    source.setDriverClassName(driver);
    source.setUrl(url);/*from  w  ww. j a  va2 s.  c  o m*/

    if (userName != null) {
        source.setUsername(userName);
    }

    if (password != null) {
        source.setPassword(password);
    }

    source.setPoolPreparedStatements(true);
    source.setInitialSize(1);
    try {
        // initial a connection
        Connection conn = source.getConnection();
        conn.close();
    } catch (SQLException sqlE) {

        logger.error("db connection error: ", sqlE);
    }
    return source;

}