最好不要将connection 和close()分开,使用完毕就关闭,这样不容易出问题。
Connection conn = null;
try{
....
rs.close();
stmt.close();
.....
}catch(Exception e){}
finally{
if(conn!=null)
try{
conn.close();
}catch(Exception e){}
}
Connection conn = null;
try{
....
rs.close();
stmt.close();
.....
}catch(Exception e){}
finally{
if(conn!=null)
try{
conn.close();
}catch(Exception e){}
}
public void close(){
try{
if(conn != null){
rs.close();
stmt.close(); //在这里CLOSE
conn.close(); //在这里CLOSE
}
}catch(Exception ee){
System.err.println("close():" + ee.getMessage());
}
}
}