就像你这样写就可以了。
try{
rs.close();
stmt.close();
conPools.freeConnection(con);
}catch(Exception e){
conPools.freeConnection(con);
try{
rs.close();
stmt.close();
conPools.freeConnection(con);
}catch(Exception e){
conPools.freeConnection(con);
时就释放了内存资源
public void close() throws SQLException
Releases a Connection's database and JDBC resources immediately instead of waiting for them to be automatically released.
Note: A Connection is automatically closed when it is garbage collected. Certain fatal errors also result in a closed Connection.
所以只用rs.close()和stmt.close()就可以了。con.close()有时会产生异常,我就遇到过这样的问题。
~classname()
{
rs.close();
stmt.close();
}
stmt=con.createStatement()
while(true){
rs=stmt.executeQuary(sql[i]);
rs.next();
String msg=rs.getString(1);
....
i++;
}
是不是最后rs被耗尽,程序崩溃呢?