PreparedStatement.close()的问题 PreparedStatement.close() 执行后 会更新db的什么地方,证明已经关闭了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用PreparedStatement的时候一般不用管数据库游标,只管java提供给你的接口层面就行。数据库游标是数据库执行层面的事,关联关系都是内部的。 statement关闭之后,所对应的游标也会关闭。但是连接可以依然保持。如果你只打开连接,但没打开任何语句,那么也不会打开任何游标。 白话连接池:连接池是为了提高连接数据库的速度,将打开的连接保存到池里,当有需要连接数据库时,不用重新连接,直接从池里拿出一个连接好的连接就行了。statement虽然是从连接对象取得的,但是关闭statement时,连接依然保持打开状态,随时准备执行其他语句。所以从上面的解释来看,关闭statement与连接池没有关系。 看一个JDBC的例子 Class.forName("com.mysql.jdbc.Driver"); String url = "jdbc:mysql://localhost:3306/sampledb"; Connection conn = DriverManager.getConnection(url, "root", "root"); Statement st = conn.createStatement(); ResultSet rs = st.executeQuery("select * from worker where id = 105"); // 在此关闭st st.close(); // 再操作结果集时会报 // Exception in thread "main" java.sql.SQLException: Operation not allowed after ResultSet closed if (rs.next()) { System.out.println(rs.getString("Id")); }Statement 的关闭只会影响有它产生的rs 结果集,关闭Statement 会连带关闭ResultSet ,但不会影响数据库的连接。同理 PreparedStatement 的关闭,也只关闭了由他产生的结果集,不会影响到数据库连接池。 JTree实现没有叶节点的根节点 任意输入一个正整数,输出他的每一位(正序输出) 有没有技术高的人啊,帮帮我 Java中监听windows OS的视窗事件 equals问题 新来的,发个自己写的JAVA开窗户游戏 请问一个有小数的数字,怎么将它变成一个整数,假如有尾位就+1 大家来讨论一下 中文问题:utf-8编码转成GBK,因为位数不同而产生字符丢掉问题!! Inprise Application Server4.1到哪去下载呀?(在线等待) 消息队列,用哪个好? java7,8 System.out.println问题
statement虽然是从连接对象取得的,但是关闭statement时,连接依然保持打开状态,随时准备执行其他语句。
所以从上面的解释来看,关闭statement与连接池没有关系。
String url = "jdbc:mysql://localhost:3306/sampledb";
Connection conn = DriverManager.getConnection(url, "root", "root");
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("select * from worker where id = 105");
// 在此关闭st
st.close();
// 再操作结果集时会报
// Exception in thread "main" java.sql.SQLException: Operation not allowed after ResultSet closed
if (rs.next()) {
System.out.println(rs.getString("Id"));
}Statement 的关闭只会影响有它产生的rs 结果集,关闭Statement 会连带关闭ResultSet ,但不会影响数据库的连接。
同理 PreparedStatement 的关闭,也只关闭了由他产生的结果集,不会影响到数据库连接池。