Statement需要关闭吗?为什么没有关闭的close()方法? 如果有为什么没有isClosed()方法? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 void close()这个方法难道还不满足楼主需要? 需要关闭 这样才能释放该Statement对象占用的资源....if(rs != null){ try{ rs.close(); rs = null; }catch(Exception e){} } if(st != null){ try{ st.close(); st = null; }catch(Exception e){} } if(con != null){ try{ con.close(); con = null; }catch(Exception e){} }.... 同意楼上的,需要关闭释放资源,其实你只要关闭Connection连接,那么Statement也就会随之关闭 ....if(rs != null){ try{ rs.close(); rs = null; }catch(Exception e){} } if(st != null){ try{ st.close(); st = null; }catch(Exception e){} } if(con != null){ try{ con.close(); con = null; }catch(Exception e){} }....就是这样,由里往外关闭啊 statment 还是要关闭的,否则可能引起内存泄露 楼主最好将 Connection、Statement 和 ResultSet 放在同一个对象中创建和关闭,否则这个逻辑就复杂了。 isClosed()方法需要特殊的支持,所以就算有也可能不能用,要验证连接是否关闭需要尝试和数据库之间交互消息,并且有过期时间的,还是用别的途径吧 关闭连接Connection.close()。isClosed();是判断是否关闭连接的吧 我一般每次连接的时候只关闭Connection 就可以了!用了这么长时间也没发生什么问题,不过为了程序的健壮性还是都关闭的比较好。 问6楼:楼主最好将 Connection、Statement 和 ResultSet 放在同一个对象中创建和关闭如何做到?? 但问题是我关多了,自己也不知道,是否已经关了如果在关了的基础上再close,那会出错的。 需要关闭statement.close();在connection.close();之前具体看程序要求 Statement Connection 是需要关闭的! Statement st = null;try{ //LZ想做什么就做什么吧。JCBC一般是 st = con.createStatement;}catch(Exception ex){ ex.printStackTrace();}finally{ if(st!=null){ st.close();//难道此方法不能满足LZ您的需要吗?}} 关闭时最好是ResultSet、Statement 、Connection这个顺序 一般关闭的时候先判断if(rs!=null){ rs.close(); rs=null;//一般是加这个的。}你再关闭的时候,rs==null,不会再去关闭了。 rs.close();你再关一次rs.close();//不会有任何操作。rs也不为空,怎么出错 rs=null;//一般是加这个的。 此处语句还有含义吗? java中的 JTable 表格 能否显现这个功能? 返回值问题--弄的我快崩溃了 在catch中加入continue,那finally中的语句是否执行 不知道哪里错了,运行不出来!! 请教一个计算日期天数的问题 想问一个问题,哪位大哥能帮个忙? 匪夷所思! Java 程序如何汉化???? 请问哪儿有JBuilder7的下载及其注册文件??? 公司要给客户做报表,从数据库返回数据,他们死活要返回的格式为Excel格式,请问我怎样才能把数据库返回的数据存为Excel的格式? 问问this 怎样在HashMap中按照默认的顺序得到K值?
这个方法难道还不满足楼主需要?
if(rs != null){
try{
rs.close();
rs = null;
}catch(Exception e){}
}
if(st != null){
try{
st.close();
st = null;
}catch(Exception e){}
}
if(con != null){
try{
con.close();
con = null;
}catch(Exception e){}
}
....
if(rs != null){
try{
rs.close();
rs = null;
}catch(Exception e){}
}
if(st != null){
try{
st.close();
st = null;
}catch(Exception e){}
}
if(con != null){
try{
con.close();
con = null;
}catch(Exception e){}
}
....
就是这样,由里往外关闭啊
statment 还是要关闭的,否则可能引起内存泄露
要验证连接是否关闭需要尝试和数据库之间交互消息,并且有过期时间的,
还是用别的途径吧
isClosed();是判断是否关闭连接的吧
用了这么长时间也没发生什么问题,
不过为了程序的健壮性还是都关闭的比较好。
楼主最好将 Connection、Statement 和 ResultSet 放在同一个对象中创建和关闭
如何做到??
如果在关了的基础上再close,那会出错的。
statement.close();在
connection.close();之前
具体看程序要求
Statement st = null;
try{
//LZ想做什么就做什么吧。JCBC一般是
st = con.createStatement;
}catch(Exception ex){
ex.printStackTrace();
}finally{
if(st!=null){
st.close();//难道此方法不能满足LZ您的需要吗?
}
}
if(rs!=null){
rs.close();
rs=null;//一般是加这个的。
}
你再关闭的时候,rs==null,不会再去关闭了。
你再关一次
rs.close();//不会有任何操作。rs也不为空,怎么出错
rs=null;//一般是加这个的。
此处语句还有含义吗?