Topic: tomcat连接池问题! |
Print this page |
1.tomcat连接池问题! | Copy to clipboard |
Posted by: tang_bo_hu Posted on: 2003-09-28 10:54 我的tomcat连接池配置如下,可是在使用的时候当多数据库操作几次以后,就提示我无法连接数据库了。请问我的配置上有什么不合理的地方吗? <Context path="" docBase="目录" debug="0" reloadable="true" crossContext="true"> <Environment name="maxExemptions" type="java.lang.Integer" value="15"/> <Parameter name="context.param.name" value="context.param.value" override="false"/> <Resource name="jdbc/mydb" auth="Container" type="javax.sql.DataSource"/> <ResourceParams name="jdbc/mydb"> <parameter> <name>factory</name> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value> </parameter> <parameter> <name>maxActive</name> <value>100</value> </parameter> <parameter> <name>maxIdle</name> <value>30</value> </parameter> <parameter> <name>maxWait</name> <value>10000</value> </parameter> <parameter> <name>username</name> <value>sa</value> </parameter> <parameter> <name>password</name> <value>sa</value> </parameter> <parameter> <name>driverClassName</name> <value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value> </parameter> <parameter> <name>url</name> <value>jdbc:microsoft:sqlserver://server:1433;DatabaseName=test;selectMethod=cursor</value> </parameter> </ResourceParams> </Context> |
2.Re:tomcat连接池问题! [Re: tang_bo_hu] | Copy to clipboard |
Posted by: helloworld Posted on: 2003-09-28 11:02 Here is an example of properly written code to use a db connection obtained from a connection pool: Connection conn = null; Statement stmt = null; // Or PreparedStatement if needed ResultSet rs = null; try { conn = ... get connection from connection pool ... stmt = conn.createStatement("select ..."); rs = stmt.executeQuery(); ... iterate through the result set ... rs.close(); rs = null; stmt.close(); stmt = null; conn.close(); // Return to connection pool conn = null; // Make sure we don't close it twice } catch (SQLException e) { ... deal with errors ... } finally { // Always make sure result sets and statements are closed, // and the connection is returned to the pool if (rs != null) { try { rs.close(); } catch (SQLException e) { ; } rs = null; } if (stmt != null) { try { stmt.close(); } catch (SQLException e) { ; } stmt = null; } if (conn != null) { try { conn.close(); } catch (SQLException e) { ; } conn = null; } } |
3.Re:tomcat连接池问题! [Re: tang_bo_hu] | Copy to clipboard |
Posted by: tang_bo_hu Posted on: 2003-09-28 11:06 楼上的,你在说什么呀? |
4.Re:tomcat连接池问题! [Re: tang_bo_hu] | Copy to clipboard |
Posted by: helloworld Posted on: 2003-09-28 11:09 "伯虎"啊: Tomcat的HOWTO中说,用了连接池要注意用完后释放,并给出了上面的例码. |
5.Re:tomcat连接池问题! [Re: tang_bo_hu] | Copy to clipboard |
Posted by: tang_bo_hu Posted on: 2003-09-28 11:43 if (rs != null) { try { rs.close(); } catch (SQLException e) { ; } rs = null; } if (stmt != null) { try { stmt.close(); } catch (SQLException e) { ; } stmt = null; } if (conn != null) { try { conn.close(); } catch (SQLException e) { ; } conn = null; } 这些我都有啊 |
6.Re:tomcat连接池问题! [Re: tang_bo_hu] | Copy to clipboard |
Posted by: wenbl Posted on: 2003-09-28 12:39 是不是操作完成以后,没有返回连接到连接池阿 |
7.Re:tomcat连接池问题! [Re: tang_bo_hu] | Copy to clipboard |
Posted by: tang_bo_hu Posted on: 2003-09-28 17:01 操作完成以后要如何 才 能吧 连接返回到 连接池呢? 我就把连接给 close了 ,文档上说close就是把连接返回到 连接池。 |
8.Re:tomcat连接池问题! [Re: tang_bo_hu] | Copy to clipboard |
Posted by: tang_bo_hu Posted on: 2003-09-30 09:12 接着我 还用了这三个参数,可是还是总死掉 <parameter> <name>removeAbandoned</name> <value>true</value> </parameter> <parameter> <name>removeAbandonedTimeout</name> <value>60</value> </parameter> <parameter> <name>logAbandoned</name> <value>true</value> </parameter> |
9.Re:tomcat连接池问题! [Re: tang_bo_hu] | Copy to clipboard |
Posted by: hitaco Posted on: 2003-10-01 12:08 查看逻辑拉,是否不同的条件下都会close |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |