本文整理匯總了Java中org.apache.commons.dbcp2.BasicDataSource.setTestOnBorrow方法的典型用法代碼示例。如果您正苦於以下問題:Java BasicDataSource.setTestOnBorrow方法的具體用法?Java BasicDataSource.setTestOnBorrow怎麽用?Java BasicDataSource.setTestOnBorrow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.dbcp2.BasicDataSource
的用法示例。
在下文中一共展示了BasicDataSource.setTestOnBorrow方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: invokeGetDataSource
import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
public DataSource invokeGetDataSource() {
BasicDataSource bds = new BasicDataSource();
bds.setDriverClassName("com.mysql.jdbc.Driver");
bds.setUrl("jdbc:mysql://127.0.0.1:3306/inst02");
bds.setUsername("root");
bds.setPassword("123456");
bds.setMaxTotal(50);
bds.setInitialSize(20);
bds.setMaxWaitMillis(60000);
bds.setMinIdle(6);
bds.setLogAbandoned(true);
bds.setRemoveAbandonedOnBorrow(true);
bds.setRemoveAbandonedOnMaintenance(true);
bds.setRemoveAbandonedTimeout(1800);
bds.setTestWhileIdle(true);
bds.setTestOnBorrow(false);
bds.setTestOnReturn(false);
bds.setValidationQuery("select 'x' ");
bds.setValidationQueryTimeout(1);
bds.setTimeBetweenEvictionRunsMillis(30000);
bds.setNumTestsPerEvictionRun(20);
return bds;
}
示例2: invokeGetDataSource
import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
public DataSource invokeGetDataSource() {
BasicDataSource bds = new BasicDataSource();
bds.setDriverClassName("com.mysql.jdbc.Driver");
bds.setUrl("jdbc:mysql://127.0.0.1:3306/inst01");
bds.setUsername("root");
bds.setPassword("123456");
bds.setMaxTotal(50);
bds.setInitialSize(20);
bds.setMaxWaitMillis(60000);
bds.setMinIdle(6);
bds.setLogAbandoned(true);
bds.setRemoveAbandonedOnBorrow(true);
bds.setRemoveAbandonedOnMaintenance(true);
bds.setRemoveAbandonedTimeout(1800);
bds.setTestWhileIdle(true);
bds.setTestOnBorrow(false);
bds.setTestOnReturn(false);
bds.setValidationQuery("select 'x' ");
bds.setValidationQueryTimeout(1);
bds.setTimeBetweenEvictionRunsMillis(30000);
bds.setNumTestsPerEvictionRun(20);
return bds;
}
示例3: init
import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
@PostConstruct
/**
* Creates security data-source to be used with the sample DB
*/
public void init() {
securityDataSource = new BasicDataSource();
securityDataSource.setDriverClassName(com.mysql.jdbc.Driver.class.getName());
securityDataSource.setUrl("jdbc:mysql://localhost:3306/java_one_2014");
securityDataSource.setUsername("java_one");
securityDataSource.setPassword("");
securityDataSource.setInitialSize(5);
securityDataSource.setMaxTotal(30);
securityDataSource.setMaxIdle(15);
securityDataSource.setMaxWaitMillis(3000);
securityDataSource.setLogAbandoned(true);
securityDataSource.setTestWhileIdle(true);
securityDataSource.setTestOnBorrow(true);
securityDataSource.setValidationQuery("select 1");
}
示例4: chatDataSource
import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
@Bean
public DataSource chatDataSource() throws ConfigurationException, IOException {
BasicDataSource datasource = new BasicDataSource();
String path = this.configuration().getString(GlobalConfig.DB_PATH);
if (path == null) {
path = GlobalConfig.DB_PATH_DEFAULT;
}
datasource.setUsername(this.configuration().getString(GlobalConfig.DB_USERNAME));
datasource.setPassword(this.configuration().getString(GlobalConfig.DB_PASSWORD));
datasource.setDriverClassName("org.h2.Driver");
datasource.setUrl("jdbc:h2:" + path);
datasource.setMaxIdle(3);
datasource.setMaxWaitMillis(5000);
datasource.setRemoveAbandonedOnBorrow(true);
datasource.setRemoveAbandonedOnBorrow(true);
datasource.setRemoveAbandonedTimeout(20);
datasource.setLogAbandoned(true);
datasource.setValidationQuery("select 1");
datasource.setMinEvictableIdleTimeMillis(3600000);
datasource.setTimeBetweenEvictionRunsMillis(1800000);
datasource.setNumTestsPerEvictionRun(10);
datasource.setTestOnBorrow(true);
datasource.setTestOnReturn(false);
datasource.addConnectionProperty("useUnicode", "yes");
datasource.addConnectionProperty("characterEncoding", "utf8");
return datasource;
}
示例5: retrySetup
import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
private void retrySetup(BasicDataSource ds) {
if (!"org.hibernate.dialect.HSQLDialect".equals(mainEnv.getDialect())) {
ds.setTestOnBorrow(dbcpEnv.isTestOnBorrow());
ds.setValidationQuery(dbcpEnv.getValidationQuery());
ds.setMaxTotal(dbcpEnv.getMaxTotal());
ds.setMinEvictableIdleTimeMillis(dbcpEnv.getMinEvictableIdleTime());
ds.setTimeBetweenEvictionRunsMillis(dbcpEnv.getTimeBetweenEvictionRuns());
ds.setNumTestsPerEvictionRun(dbcpEnv.getNumTestsPerEvictionRun());
ds.setTestWhileIdle(dbcpEnv.isTestWhileIdle());
ds.setTestOnReturn(dbcpEnv.isTestOnReturn());
}
}
示例6: setupDataSource
import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
private static DataSource setupDataSource(String dbUrl, String dbUserName, String dbPassword) {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl(dbUrl + "?useSSL=false&serverTimezone=UTC");
dataSource.setUsername(dbUserName);
dataSource.setPassword(dbPassword);
dataSource.setValidationQuery("SELECT 1;");
dataSource.setTestOnBorrow(true); // test each connection when borrowing from the pool with the validation query
dataSource.setMaxConnLifetimeMillis(1000 * 60 * 60); // max connection life time 1h. mysql drops connection after 8h.
return dataSource;
}
示例7: setImcmsDataSourceProperties
import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
private void setImcmsDataSourceProperties(BasicDataSource basicDataSource) {
basicDataSource.setDriverClassName(imcmsProperties.getProperty("JdbcDriver"));
basicDataSource.setUrl(imcmsProperties.getProperty("JdbcUrl"));
basicDataSource.setUsername(imcmsProperties.getProperty("User"));
basicDataSource.setPassword(imcmsProperties.getProperty("Password"));
basicDataSource.setTestOnBorrow(true);
basicDataSource.setValidationQuery("select 1");
basicDataSource.setDefaultAutoCommit(false);
basicDataSource.setMaxTotal(20);
basicDataSource.setMaxTotal(Integer.parseInt(imcmsProperties.getProperty("MaxConnectionCount")));
}
示例8: dataSource
import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
@Scope("prototype")
@Bean(destroyMethod = "close")
public DataSource dataSource() {
BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName(env.getRequiredProperty("JdbcDriver"));
ds.setUsername(env.getRequiredProperty("User"));
ds.setPassword(env.getRequiredProperty("Password"));
ds.setTestOnBorrow(true);
ds.setValidationQuery("select 1");
ds.setMaxTotal(1);
return ds;
}
示例9: registerDataSource
import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
/**
* register the data source for H2 DB
*
* @return pooling database object
*/
private static BasicDataSource registerDataSource() {
System.setProperty("h2.baseDir", BASE_DIR);
// create a database connection
String user = AppConfig.getProperty("dbUser");
String password = AppConfig.decryptProperty("dbPassword");
String connectionURL = AppConfig.getProperty("dbConnectionURL");
if(connectionURL != null && connectionURL.contains("CIPHER=")) {
password = "filepwd " + password;
}
String validationQuery = "select 1";
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName(DB_DRIVER);
dataSource.setMaxTotal(MAX_ACTIVE);
dataSource.setTestOnBorrow(TEST_ON_BORROW);
dataSource.setMinIdle(MIN_IDLE);
dataSource.setMaxWaitMillis(MAX_WAIT);
dataSource.setValidationQuery(validationQuery);
dataSource.setUsername(user);
dataSource.setPassword(password);
dataSource.setUrl(connectionURL);
return dataSource;
}
示例10: SQLDatabase
import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
/**
*
* Constructor for a database instance.
*
* @param jdbcInfo the driver you are using
* @param username login name
* @param password password
* @param database database name
* @param host host for the connection
* @param port port of the SQL server
*
*/
public SQLDatabase(SQLDatabaseType jdbcInfo, String username, String password, String database, String host,
int port) {
this.jdbcInfo = jdbcInfo;
this.username = username;
this.password = password;
this.host = host;
this.port = port;
this.database = database;
BasicDataSource ds = new BasicDataSource();
String urlPrefix = jdbcInfo.getURLPrefix(this.host, this.database, this.port)
+ "?autoReconnect=true&useSSL=false&serverTimezone=UTC";
ds.setUrl(urlPrefix);
ds.setUsername(username);
ds.setPassword(password);
ds.setDriverClassName(jdbcInfo.getDriverName());
ds.setPoolPreparedStatements(true);
ds.setTestOnBorrow(true);
ds.setRemoveAbandonedOnBorrow(true);
ds.setRemoveAbandonedOnMaintenance(true);
ds.setMaxOpenPreparedStatements(100);
ds.setMaxConnLifetimeMillis(1000 * 60 * 60);
dataSource = ds;
setValidationQuery();
}