当前位置: 技术问答>java相关
朋友 帮忙!
来源: 互联网 发布时间:2015-03-15
本文导语: Connection connection = DriverManager.getConnection(url,"",""); Statement statement = connection.createStatement(); ResultSet rs = statement.executeQuery(sql); connection.close(); statement 应该是依靠这个 connection ,若 connection.close(); 是否相应的 stat...
Connection connection = DriverManager.getConnection(url,"","");
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery(sql);
connection.close();
statement 应该是依靠这个 connection ,若 connection.close();
是否相应的 statement 被释放,而不必执行statement.close()。
statement automatically closed 发生在什么时候.请指教!多谢
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery(sql);
connection.close();
statement 应该是依靠这个 connection ,若 connection.close();
是否相应的 statement 被释放,而不必执行statement.close()。
statement automatically closed 发生在什么时候.请指教!多谢
|
Connection is expensive, so if you want to execute more than one statements with one connection, you want to keep the connection open but keep on creating/closing statement.
However, this only apply to JDBC 2.0 or easier, because it is not a good design. Busy or huge applications want to share connections (using connection pool). So with J2ee V2.0, it is possible to create a statement without a connection. What you do is to create all statements and keep them in memory. When you are ready to execute one, open a connection.
However, this only apply to JDBC 2.0 or easier, because it is not a good design. Busy or huge applications want to share connections (using connection pool). So with J2ee V2.0, it is possible to create a statement without a connection. What you do is to create all statements and keep them in memory. When you are ready to execute one, open a connection.
|
以下我对jdk中的文档理解,请参考
1 关闭Connection 将引起对此Connection所拥有的statement进行garbage collection,
2 关闭Statement 将自动关闭Statement所对应的ResultSet
3 虽然1是可以自动执行,但为了系统效率,还是应该在使用完Statement时手动关闭他
1 关闭Connection 将引起对此Connection所拥有的statement进行garbage collection,
2 关闭Statement 将自动关闭Statement所对应的ResultSet
3 虽然1是可以自动执行,但为了系统效率,还是应该在使用完Statement时手动关闭他
|
关注~~~~~~~~~~
|
插播:
请各位高手帮忙给看看
http://www.csdn.net/expert/topic/463/463710.shtm
http://www.csdn.net/expert/topic/463/463555.shtm
请各位高手帮忙给看看
http://www.csdn.net/expert/topic/463/463710.shtm
http://www.csdn.net/expert/topic/463/463555.shtm