Statement stmt = conn.createStatement();
1.你的stmt是在try块里面定义的,到了finally就已经超过stmt变量的作用域范围了,当然无法通过编译,改成:
Statement stmt = null;
try{
stmt = conn.createStatement();
...
}finally{...}2.这些close方法都可能抛出SQLException的,必须要再try一次
3.conn, rs, stmt可能会是null,要判断一下:
finally{
try{
if(null != rs) rs.close();
if(null != stmt) stmt.close();
if(null != conn) conn.close();
}catch(SQLException se){}
}
1.你的stmt是在try块里面定义的,到了finally就已经超过stmt变量的作用域范围了,当然无法通过编译,改成:
Statement stmt = null;
try{
stmt = conn.createStatement();
...
}finally{...}2.这些close方法都可能抛出SQLException的,必须要再try一次
3.conn, rs, stmt可能会是null,要判断一下:
finally{
try{
if(null != rs) rs.close();
if(null != stmt) stmt.close();
if(null != conn) conn.close();
}catch(SQLException se){}
}
return rs;
}catch(...){
return null;
}finally{
...
}
{
try
{
if(rs !=null)
rs.close();
if(conn !=null)
conn.close();
}
catch(SQLException ex) { System.err.println("db.executeUpdate: " + ex.getMessage());
}
} 然后在JSP中调用,db.Close(); 但是出现错误信息:javax.servlet.ServletException: Logon failed: Connection reset
如何解决?还是我的代码写的有问题?