import java.sql.Connection;
import java.sql.SQLException;import com.mchange.v2.c3p0.ComboPooledDataSource;public class DatabaseAccessHelper { private static ComboPooledDataSource dataSource; static {
try {
dataSource = new ComboPooledDataSource(); //dataSource.setDriverClass("com.mysql.jdbc.Driver");
dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/pb");
dataSource.setUser("root");
dataSource.setPassword("123456"); dataSource.setMinPoolSize(3);
dataSource.setMaxPoolSize(20);
dataSource.setInitialPoolSize(5);
dataSource.setNumHelperThreads(5); dataSource.setCheckoutTimeout(500);
dataSource.setAutoCommitOnClose(false); dataSource.setMaxIdleTime(18000);
dataSource.setIdleConnectionTestPeriod(3600);
dataSource.setTestConnectionOnCheckin(true);
dataSource.setPreferredTestQuery("select count(*) from systemurl"); } catch (Exception e) {
throw new RuntimeException(e);
}
} public static Connection getConnection() throws SQLException {
return dataSource.getConnection();
} public static void close() {
dataSource.close();
}
}注意注释部分,给或不给或给错误的驱动,C3P0均能正确连接,求解。
解决方案 »
- Jboss + Jpa多数据库本地事务的问题
- tomcat集群session共享问题,高手求解
- 请教各位java导Excel的问题
- 大家帮帮忙看看这个异常什么意思
- xfire 调用.net webservice?
- 紧急求助: 我用ireport 2.0.5制作的报表怎么不出表格线!ireport侧生成pdf文件是可看到表格线的,但java程序里用到它对应的.jasper时,生成的报表却没有表格线,这是为什么!!!!
- 关于<<J2EE构建企业级应用解决方案>>中的一个例子
- 靠J2EE吃饭的人-你们过得好吗?--J2EE程序员调查>>高分调查.
- tomcat下如何配置?
- spring mvc的拦截器如何获取控制器里面的map?
- 求一个hibernate左外连接的mapping配置
- jsp页面提交表单方式
DriverManager.getConnection has been modified to utilize the Java SE
Service Provider mechanism to automatically load JDBC Drivers. This removes
the need to invoke Class.forName.简单的说,所有的java.sql.Diver在加载的时候,会到DriverManager注册一下。程序调用DriverManager.getConnection的时候,DriverManager会拿connnectionUrl到所有注册过的Driver上挨个试,直到成功得到Connection对象。