BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUsername("username"); dataSource.setPassword("password"); dataSource.setUrl("jdbc:mysql://<host>:<port>/<database>"); dataSource.setMaxActive(10); dataSource.setMaxIdle(5); dataSource.setInitialSize(5); dataSource.setValidationQuery("SELECT 1");
/** * Get JDBC Username for JDBC source, usually it's from the <C>AdaptorConfig</C> passed to constructor. * @return The JDBC Username. */ public String getJdbcUser() { return dataSource.getUsername(); }
/** * Create a new <C>java.sql.Connection</C> for this JDBC source. * @return * @throws SQLException */ public Connection getConnection() throws SQLException { return dataSource.getConnection(); }
BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName("driverClassName"); ds.setUrl("jdbc://..."); ds.setUsername("username"); ds.setPassword("password");
public DataSourceProvider() { this.basicDataSource = new BasicDataSource(); }
/** * To close the adaptor, because we need to close all connections on this JDBC source. * @throws IOException If close failed. */ @Override public void close() throws IOException { try { dataSource.close(); } catch (SQLException e) { throw new IllegalStateException(e); } }
/** * Get JDBC Url for JDBC source, usually it's from the <C>AdaptorConfig</C> passed to constructor. * @return The JDBC Url. */ public String getJdbcUrl() { return dataSource.getUrl(); }
protected void initializeDatabaseConnection(Configuration conf) throws Exception { if (dbcpDataSource == null) { synchronized (this) { if (dbcpDataSource == null) { Properties props = getConnectionPoolProperties(conf); dbcpDataSource = BasicDataSourceFactory.createDataSource(props); } } } }
/** * Get JDBC Driver class name for JDBC source, usually it's from the <C>AdaptorConfig</C> passed to constructor. * @return JDBC Driver class name. */ public String getJdbcDriver() { return dataSource.getDriverClassName(); }
/** * Get JDBC Password for JDBC source, usually it's from the <C>AdaptorConfig</C> passed to constructor. * @return The JDBC password. */ public String getJdbcPassword() { return dataSource.getPassword(); }
public final class Database { private static final BasicDataSource dataSource = new BasicDataSource(); static { dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl("jdbc:mysql://localhost:3306/data"); dataSource.setUsername("USERNAME"); dataSource.setPassword("PASSWORD"); } private Database() { // } public static Connection getConnection() throws SQLException { return dataSource.getConnection(); } }
public void close() { try { dataSource.close(); } catch (Exception e) { throw new RuntimeException(e); } }
public synchronized Connection getConnection() { try { return dataSource.getConnection(); } catch (SQLException e) { throw new RuntimeException(e); } } }
@Override public String getCurrentDBUrl() { DataSource ds = this.jt.getDataSource(); if (ds == null) { return StringUtils.EMPTY; } BasicDataSource bds = (BasicDataSource)ds; return bds.getUrl(); }
private void createBasicDataSource() { BasicDataSource bds = new BasicDataSource(); bds.setDriverClassName( jdbcDriver ); bds.setUrl( jdbcUrl ); bds.setUsername( jdbcUser ); bds.setPassword( jdbcPass ); dataSource = bds; }
/** * Closes the connections to the database. * * @throws SQLException */ public void close() throws SQLException { ( (BasicDataSource) dataSource ).close(); }
private DataSource setUpEventTraceDataSource() { BasicDataSource result = new BasicDataSource(); result.setDriverClassName(eventTraceDataSourceConfiguration.getDriver()); result.setUrl(eventTraceDataSourceConfiguration.getUrl()); result.setUsername(eventTraceDataSourceConfiguration.getUsername()); result.setPassword(eventTraceDataSourceConfiguration.getPassword()); return result; }
public void close() { try { this.dataSource.close(); } catch(SQLException e) { throw new VoldemortException("Exception while closing connection pool.", e); } }
private DataSource getDataSource() { BasicDataSource ds = new BasicDataSource(); ds.setUrl("jdbc:mysql://localhost:3306/test"); ds.setUsername("root"); ds.setPassword(""); ds.setDriverClassName("com.mysql.jdbc.Driver"); return ds; }
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; }