本文整理汇总了Java中org.apache.tomcat.dbcp.dbcp2.BasicDataSource.setDriverClassName方法的典型用法代码示例。如果您正苦于以下问题:Java BasicDataSource.setDriverClassName方法的具体用法?Java BasicDataSource.setDriverClassName怎么用?Java BasicDataSource.setDriverClassName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tomcat.dbcp.dbcp2.BasicDataSource
的用法示例。
在下文中一共展示了BasicDataSource.setDriverClassName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ConnectionDB
import org.apache.tomcat.dbcp.dbcp2.BasicDataSource; //导入方法依赖的package包/类
private ConnectionDB ()
{
pool = new BasicDataSource();
pool.setDriverClassName("com.mysql.jdbc.Driver");
pool.setUsername("root");
pool.setPassword("1111");
pool.setUrl("jdbc:mysql://localhost/videogameshop");
pool.setInitialSize(40);
}
示例2: newDataSource
import org.apache.tomcat.dbcp.dbcp2.BasicDataSource; //导入方法依赖的package包/类
/**
* Create a new {@code DataSource}.
* <br>
* The lifecycle of the created instance is <strong>NOT</strong>
* managed by baseline. To create a {@code DataSource} whose lifecycle
* is managed, use {@link #newManagedDataSource(Environment, DatabaseConfiguration)}.
*
* @param database database configuration block for configuring the {@code DataSource}
* @return valid, new {@code DataSource} instance
*/
public static DataSource newDataSource(DatabaseConfiguration database) {
BasicDataSource dataSource = new BasicDataSource();
// attempt to load the driver class
dataSource.setDriverClassName(database.getDriverClass());
// username and password
// only sets them if the value is not null/empty
if (!(database.getUsername() == null || database.getUsername().isEmpty())) {
dataSource.setUsername(database.getUsername());
}
if (!(database.getPassword() == null || database.getPassword().isEmpty())) {
dataSource.setPassword(database.getPassword());
}
// other properties
dataSource.setUrl(database.getUrl());
dataSource.setDefaultTransactionIsolation(database.getDefaultTransactionIsolation().getLevel());
dataSource.setDefaultAutoCommit(database.isAutoCommit());
dataSource.setTestOnBorrow(database.isCheckConnectionOnBorrow());
dataSource.setTestOnReturn(database.isCheckConnectionOnReturn());
dataSource.setMinIdle(database.getMinTotalConnections());
dataSource.setMaxTotal(database.getMaxTotalConnections());
dataSource.setMaxIdle(database.getMaxIdleConnections());
dataSource.setMaxWaitMillis(database.getAcquireConnectionTimeout());
dataSource.setDefaultQueryTimeout(database.getQueryTimeout() <= 0 ? null : database.getQueryTimeout());
dataSource.setTestWhileIdle(database.isCheckConnectionWhenIdle());
dataSource.setTimeBetweenEvictionRunsMillis(database.getIdleConnectionCheckInterval());
dataSource.setMinEvictableIdleTimeMillis(database.getCloseIdleConnectionAfter());
dataSource.setValidationQuery(database.getValidationQuery());
dataSource.setValidationQueryTimeout((int) database.getValidationQueryTimeout());
dataSource.setAccessToUnderlyingConnectionAllowed(false);
dataSource.setDefaultAutoCommit(false);
return dataSource;
}