如果您无法控制服务器,那么您将迷路。只需自己创建连接池,而不是让容器来做。
我建议为此使用c3p0(这比Tomcat的内置DBCP更好,因为它被锁定到单个线程)。将c3p0库放入中,
/WEB-INF/lib并根据其文档进行创建:
ComboPooledDataSource dataSource = new ComboPooledDataSource(); dataSource.setDriverClass("org.postgresql.Driver"); dataSource.setJdbcUrl("jdbc:postgresql://localhost/testdb");dataSource.setUser("dbuser");dataSource.setPassword("dbpassword"); // ...Connection connection = null;// ...try { connection = dataSource.getConnection(); // ...} finally { // ... if (connection != null) try { connection.close(); } catch (SQLException logOrIgnore) {} // Always close resources in finally!}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)