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

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

Introduction

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

Prototype

public synchronized void setDriver(Driver driver) 

Source Link

Document

Sets the JDBC Driver instance to use for this pool.

Usage

From source file:com.twosigma.beaker.sql.JDBCClient.java

public BasicDataSource getDataSource(String uri) throws DBConnectionException {
    synchronized (this) {
        try {//from ww  w  .j a  v  a  2s . c om

            BasicDataSource ds = dsMap.get(uri);
            if (ds == null) {
                Driver driver = null;
                for (Driver test : drivers) {
                    if (test.acceptsURL(uri)) {
                        driver = test;
                        break;
                    }
                }
                if (driver == null) {
                    DriverManager.getDriver(uri);
                }
                ds = new BasicDataSource();
                ds.setDriver(driver);
                ds.setUrl(uri);
                dsMap.put(uri, ds);
            }
            return ds;

        } catch (SQLException e) {
            //Logger.getLogger(JDBCClient.class.getName()).log(Level.SEVERE, null, e);
            throw new DBConnectionException(uri, e);
        }
    }
}