C3P0 连接池

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/cuilianji/article/details/83642000
一、有三种获取具备连接池特性的数据源的途径:
1. 直接实例化 ComboPooledDataSource bean;
2. use the DataSources factory class;
3. "build your own" pool-backed DataSource by directly instantiating PoolBackedDataSource and setting its ConectionPoolDataSource.

二、配置
无论以什么方式获得了DataSource,c3p0都可以提供一个名为 c3p0.properties 的文件来配置该数据源,从c3p0-0.9.1开始,还可以通过文件c3p0-config.xml来进行高级配置。如果为提供任何配置文件数据源仍然可以使用缺省配置来工作。

三、Spring API LocalSessionFactoryBean建议使用spring配置的数据源而略去使用Hibernate connection provider参数于 setHibernateProperties(Properties hibernateProperties)
展开阅读全文

JDBC连接池c3p0的问题

07-05

测试CP30连接池,怎么报这样的异常? rnrnrnrnimport java.beans.PropertyVetoException; rnimport java.sql.Connection; rnimport java.sql.SQLException; rnimport com.mchange.v2.c3p0.ComboPooledDataSource; rnrnpublic final class ConnectionManager rnrn private static ConnectionManager instance; rn private static ComboPooledDataSource dataSource; rnrn private ConnectionManager() throws SQLException, PropertyVetoException rn dataSource = new ComboPooledDataSource(); rnrn dataSource.setUser("root"); rn dataSource.setPassword("root"); rn dataSource.setJdbcUrl("jdbc:mysql://loachost:3306/test"); rn dataSource.setDriverClass("com.mysql.jdbc.Driver"); rn dataSource.setInitialPoolSize(5); rn dataSource.setMinPoolSize(1); rn dataSource.setMaxPoolSize(10); rn dataSource.setMaxStatements(50); rn dataSource.setMaxIdleTime(60); rn rnrn public static final ConnectionManager getInstance() rn if (instance == null) rn try rn instance = new ConnectionManager(); rn catch (Exception e) rn e.printStackTrace(); rn rn rn return instance; rn rnrn public synchronized final Connection getConnection() rn Connection conn = null; rn try rn conn = dataSource.getConnection(); rn catch (SQLException e) rn e.printStackTrace(); rn rn return conn; rn rn rnrnrnimport java.sql.Connection; rnimport java.sql.PreparedStatement; rnimport java.sql.ResultSet; rnimport java.sql.SQLException; rnrnrnpublic class ConnectionDemo rnrn public static void main(String[] args) rn System.out.println("使用连接池................................"); rn for (int i = 0; i < 20; i++) rn long beginTime = System.currentTimeMillis(); rn Connection conn = ConnectionManager.getInstance().getConnection(); rn try rn PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM t_fmscpy200"); rn ResultSet rs = pstmt.executeQuery(); rn while (rs.next()) rn rn catch (SQLException e) rn e.printStackTrace(); rn finally rn try rn conn.close(); rn catch (SQLException e) rn e.printStackTrace(); rn rn rnrn long endTime = System.currentTimeMillis(); rn System.out.println("第" + (i + 1) + "次执行花费时间为:" + (endTime - beginTime)); rn rnrn rn rnrnrn2010-7-4 21:12:52 com.mchange.v2.log.MLog rn信息: MLog clients using java 1.4+ standard logging. rn2010-7-4 21:12:53 com.mchange.v2.c3p0.C3P0Registry banner rn信息: Initializing c3p0-0.9.2-pre1 [built 27-May-2010 01:00:49 -0400; debug? true; trace: 10] rnException in thread "main" java.lang.NoSuchMethodError: com.mchange.v2.async.ThreadPoolAsynchronousRunner.(IZLjava/util/Timer;Ljava/lang/String;)V rnat com.mchange.v2.c3p0.impl.C3P0PooledConnectionPoolManager.createTaskRunner(C3P0PooledConnectionPoolManager.java:132) rnat com.mchange.v2.c3p0.impl.C3P0PooledConnectionPoolManager.poolsInit(C3P0PooledConnectionPoolManager.java:143) rnat com.mchange.v2.c3p0.impl.C3P0PooledConnectionPoolManager.(C3P0PooledConnectionPoolManager.java:262) rnat com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getPoolManager(AbstractPoolBackedDataSource.java:508) rnat com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128) rnat ConnectionManager.getConnection(ConnectionManager.java:39) rnat ConnectionDemo.main(ConnectionDemo.java:14) rnrn结果报这样的异常,jar用到的是cp300.9.1.2.jar rn 论坛

没有更多推荐了,返回首页