摘录一些别人的说法: If you close the connection, Statements created from that connection will be closed. If you close the statement, Resultets open from that statement will be close.Always close ResultSet, Statements and Connections in that order. If you don't close the statements or resultsets they might hang around until the get garbage collected, and even after that they might take valuable resources on the database server. I always uses a finally clause with the close logic as below. If you don't have separete try clauses for each close operation a failed resultSet might leave a connection open, and we don't want that.
If you close the connection, Statements created from that connection will be closed.
If you close the statement, Resultets open from that statement will be close.Always close ResultSet, Statements and Connections in that order. If you don't close the statements or resultsets they might hang around until the get garbage collected, and even after that they might take valuable resources on the database server. I always uses a finally clause with the close logic as below. If you don't have separete try clauses for each close operation a failed resultSet might leave a connection open, and we don't want that.
用一个statement是可以多次查询的,不是每ResultSet用完关闭.
try {
......
} catch( Exception e ) {
} finally {
res.close();
stmt.close();
con.close();
}
你这样写能成功吗???我为什么都不成功。。我是这样写的
try {
......
} catch( Exception e ) {
} finally {
try{
res.close();
stmt.close();
con.close();
}catch(Exception e){
}
}
需要的请给我mail: [email protected]
你这样写能成功吗???我为什么都不成功。。我是这样写的
try {
......
} catch( Exception e ) {
} finally {
try{
res.close();
stmt.close();
}catch(Exception e){
}finally {
try {
con.close();
}catch(...) {}
}
}Connection 最重要,如果前面的close抛出异常,你的connection就没关掉