当前位置: 首页>>代码示例>>Java>>正文


Java BasicDataSource.setDriverClassName方法代码示例

本文整理汇总了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); 

}
 
开发者ID:AlbertoHdezS,项目名称:shop_java_project,代码行数:11,代码来源:ConnectionDB.java

示例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;
}
 
开发者ID:redbooth,项目名称:baseline,代码行数:47,代码来源:Databases.java


注:本文中的org.apache.tomcat.dbcp.dbcp2.BasicDataSource.setDriverClassName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。