这个例子比较清晰,WEB多线程使我的代码执行变成如下步骤,只有最后一个Statement被释放,其它没有成功释放。stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = stmt1.executeQuery(strSQL);stmt2 = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = stmt2.executeQuery(strSQL);stmt3 = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = stmt3.executeQuery(strSQL);stmt1.close();
stmt2.close();
stmt3.close();
rs = stmt1.executeQuery(strSQL);stmt2 = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = stmt2.executeQuery(strSQL);stmt3 = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = stmt3.executeQuery(strSQL);stmt1.close();
stmt2.close();
stmt3.close();
解决方案 »
- 多线程死锁问题
- 一个构造函数的小问题, 请高手明示:
- 使用Java Applet访问数据库
- java和c#如何实现des交叉加密解密
- 看不懂这句英文:)大家赐教
- 求SDK中库的设置~~
- 如何校驗用戶輸入繁體
- 加分了。想用jmf写一个视频会议软件请大家给些写服务器端和客户端的架构建议,客户端想用applet
- 我注册了sms.163.com的短信有没有直接登陆的url???
- GenericJDBCException: could not execute query
- 谁看过《JAVA数据库宝典》-电子工业出版社
- ☆★☆★substring不执行问题,执行完substring上一行就退出函数了☆★☆★
rs = stmt1.executeQuery(strSQL);stmt2 = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = stmt2.executeQuery(strSQL);stmt3 = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = stmt3.executeQuery(strSQL);stmt1.close();
stmt2.close();
stmt3.close();
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);rs = stmt.executeQuery(strSQL);
while(re.next){
do...
}rs = stmt.executeQuery(strSQL);
while(re.next){
do...
}rs = stmt.executeQuery(strSQL);
while(re.next){
do...
}stmt.close();
^@^
是不是?
哈哈
rs.close();rs = stmt.executeQuery(strSQL);
rs.close();rs = stmt.executeQuery(strSQL);
rs.close();stmt.close();
或者用RowSet来代替ResultSet,RowSet可以在关闭数据库连接的情况下仍然持有数据库查询所得的数据
这个问题的根本是我提供了一个方法
RunSQLReturnRS(strSQL)
这个方法返回了ResultSet,而连接池必须在ResultSet使用完毕后才能得到空闭的Connection,才能将Connection给其它请求使用。rongrongGsr:不知RowSet和ResultSet具体如何操作?
另外,在一个Connection创建多个Statement有什么说法,听说Oracle可以,而SQL2K不行,请高手赐教。
* Releases this <code>Statement</code> object's database
* and JDBC resources immediately instead of waiting for
* this to happen when it is automatically closed.
* It is generally good practice to release resources as soon as
* you are finished with them to avoid tying up database
* resources.
* <P><B>Note:</B> A <code>Statement</code> object is automatically closed when it is
* garbage collected. When a <code>Statement</code> object is closed, its current
* <code>ResultSet</code> object, if one exists, is also closed.
*
* @exception SQLException if a database access error occurs
*/
void close() throws SQLException;
看jdk1.3的源码,statement.close()被关闭时,它所创建的ResultSet会被自动关闭。
而Connection.close()时,其下的statement并没有自动被释放,需要手动释放。
rs.close();rs = stmt.executeQuery(strSQL2);
rs.close();rs = stmt.executeQuery(strSQL3);
rs.close();这样执行有时候会失败。stmt要重新创建。