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:nl.surfnet.coin.db.AbstractInMemoryDatabaseTest.java

/**
 * We use an in-memory database - no need for Spring in this one - and
 * populate it with the sql statements in test-data-eb.sql
 * /*from  ww w  . java2s  .  c o m*/
 * @throws Exception
 *           unexpected
 */
@Before
public void before() throws Exception {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setPassword("");
    dataSource.setUsername("sa");
    String url = getDataSourceUrl();
    dataSource.setUrl(url);
    dataSource.setDriverClassName("org.hsqldb.jdbcDriver");

    jdbcTemplate = new JdbcTemplate(dataSource);

    ClassPathResource resource = new ClassPathResource(getMockDataContentFilename());
    logger.debug("Loading database content from " + resource);
    if (resource.exists()) {
        final String sql = IOUtils.toString(resource.getInputStream());
        final String[] split = sql.split(";");
        for (String s : split) {
            if (!StringUtils.hasText(s)) {
                continue;
            }
            jdbcTemplate.execute(s + ';');
        }
    }
}

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 ww  .j  a va2 s . co 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;// ww w  .j  a  v a  2s . c o  m
}

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 ww  w.  j av  a2s  . c  om

    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  ww.  j  av a 2 s  .  c  om*/
 * 
 * @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);// ww w  .ja  v a  2  s .  co m
    source.setUrl(url);

    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;

}