日期:2014-05-18  浏览次数:20916 次

数据库连接关闭错误! java.lang.NullPointerException
1.如标题所示,我在关闭数据库资源时报出了这个错误,请大家分析一下问题在哪里。
2.关于关闭连接,在什么时候关闭比较合适?

------解决方案--------------------
shutdown abort;
startup restrict;
shutdown immediate;


------解决方案--------------------
错误提示拿来瞧瞧。。。
------解决方案--------------------
具体的错误信息,
用完就close();
------解决方案--------------------
不多提供些具体信息,大家很难帮你解答阿
------解决方案--------------------
java.lang.NullPointerException空指针错误吗
应该是哪里有null的东西
代码?错误信息?
------解决方案--------------------
Connection cn = null;
PreparedStatement st = null;
ResultSet rset = null;
try
{
cn = //取得Connection
st = //取得PreparedStatement
st.setString(1, userId);
rset = st.executeQuery();//ResultSet
if ( rset.next() )
{
//循环rs
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
//关闭
try { if ( rset!=null) rset.close(); }catch (Exception e){ }
try { if ( st!=null) st.close(); }catch (Exception e){ }
try { if ( cn!=null) cn.close(); }catch (Exception e){ }
}
------解决方案--------------------
//用finally


finally {
try {
if(rs != null) {
rs.close();
rs = null;
}
if(stmt != null) {
stmt.close();
stmt = null;
}
if(conn != null) {
conn.close();
conn = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
------解决方案--------------------
你报棏是空指针异常