Java Code Examples for org.apache.commons.dbcp.BasicDataSource#setConnectionProperties()

The following examples show how to use org.apache.commons.dbcp.BasicDataSource#setConnectionProperties() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JDBCDataSourceProvider.java    From eagle with Apache License 2.0 6 votes vote down vote up
@Override
public DataSource get() {
    BasicDataSource datasource = new BasicDataSource();
    datasource.setDriverClassName(config.getDriverClassName());
    datasource.setUsername(config.getUsername());
    datasource.setPassword(config.getPassword());
    datasource.setUrl(config.getConnection());
    datasource.setConnectionProperties(config.getConnectionProperties());
    LOGGER.info("Register JDBCDataSourceShutdownHook");
    Runtime.getRuntime().addShutdownHook(new Thread("JDBCDataSourceShutdownHook") {
        @Override
        public void run() {
            try {
                LOGGER.info("Shutting down data source");
                datasource.close();
            } catch (SQLException e) {
                LOGGER.error("SQLException: {}", e.getMessage(), e);
                throw new IllegalStateException("Failed to close datasource", e);
            }
        }
    });
    return datasource;
}
 
Example 2
Source File: JdbcMetadataHandler.java    From eagle with Apache License 2.0 6 votes vote down vote up
public JdbcMetadataHandler(Config config) {
    try {
        //JdbcSchemaManager.getInstance().init(config);
        BasicDataSource bDatasource = new BasicDataSource();
        bDatasource.setDriverClassName(config.getString(MetadataUtils.JDBC_DRIVER_PATH));
        if (config.hasPath(MetadataUtils.JDBC_USERNAME_PATH)) {
            bDatasource.setUsername(config.getString(MetadataUtils.JDBC_USERNAME_PATH));
            bDatasource.setPassword(config.getString(MetadataUtils.JDBC_PASSWORD_PATH));
        }
        bDatasource.setUrl(config.getString(MetadataUtils.JDBC_CONNECTION_PATH));
        if (config.hasPath(MetadataUtils.JDBC_CONNECTION_PROPERTIES_PATH)) {
            bDatasource.setConnectionProperties(config.getString(MetadataUtils.JDBC_CONNECTION_PROPERTIES_PATH));
        }
        this.dataSource = bDatasource;
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
    }
}
 
Example 3
Source File: ConnectionPoolingIT.java    From snowflake-jdbc with Apache License 2.0 5 votes vote down vote up
private void setUpDBCPConnection()
{
  bds = new BasicDataSource();
  bds.setDriverClassName(BaseJDBCTest.DRIVER_CLASS);
  bds.setUsername(this.user);
  bds.setPassword(this.password);
  bds.setUrl(connectStr);

  String propertyString = String.format(
      "ssl=%s;db=%s;schema=%s;account=%s;",
      this.ssl, this.database, this.schema, this.account
  );
  bds.setConnectionProperties(propertyString);
}