try{
conn=ds.getConnection();
stmt=conn.createstatement();
rs=stmt.executeQuery("");
......rs.close();//-----------------1
rs=null;
stmt.close();
stmt=null;
conn.close();
conn=null;//------------------1
}
catch(Exception e){
....}
finally{//--------------------2
if(rs!=null){
try{
rs.close();}
catch(Exception e){...}
rs=null;
}
if(stmt!=null){
try{
stmt.close();}
catch(Exception e){...}
stmt=null;
}
if(conn!=null){
try{
conn.close();}
catch(Exception e){...}
conn=null;
}---------------------------2
}
困惑:
我怎么觉得1处的三个close是多余的,反正finally总是执行的,为什么不单留下finally里的处理。
在1处处理一下的目的是神马?线程安全
解决方案 »
- 有玩uddi的吗?
- 关于spring IDE装好后的问题?
- MLDN 视频的
- java.lang.NoClassDefFoundError: org/jaxen/BaseXPath 使用idea时候遇到的问题
- 如何调用已生成的WEB SERVICES?
- 有没有学习EJB3的教程或资料?
- 在javaBean中怎样实现自动编号?
- 关于事务和实体bean的问题
- 请问如何让JTable 获得焦点和选中某一行,谢谢!!!
- java.sql.SQLException: Access denied for user 'ssh'@'localhost' (using password:
- 怎样防止hibernate加载时删除数据库表的数据
- 关于 jstl输出问题
rs.close();//-----------------1
rs=null;
stmt.close();
stmt=null;
conn.close();
conn=null;//------------------1
部分是多余的因为与finally中重复了但如果说用=null代替close方法,还要研究一下,close方法关闭的资源可能不止它自身对象