我现在用这个方法关闭
 } finally {
   if (rs != null) rs.close();
   if (st != null) st.close();
   if (con != null) con.close();
 }
假设关闭st的时候发生了错误,那么con就关闭不了了!
关闭rs或关闭st的时候会不会出现错误呢?
如果关闭rs或关闭st的时候出现错误,那么con就关闭不了了阿

解决方案 »

  1.   

    } finally {
    try {
       if (rs != null) rs.close();
       if (st != null) st.close();
       if (con != null) con.close();
    }
    finally {
    rs= null;
    st=nul;;
    conn= null;
    }
     }
      

  2.   

    唉。。这个问题。你到这里来看看吧
    http://www.hibernate.org.cn/viewtopic.php?t=13649这里全是讨论这个问题的。。
    名字是: 你擦了吗?确定擦了?真的确定擦了?
      

  3.   

    to kongxiangli(笑看红尘)
    你这个方法也没有关闭阿,只是负值为null了
      

  4.   

    其实你的那个写法就是为了保险起见写的了,其实只要关闭连接就可以了,只要关闭连接,rs和st就会自动关闭。照kongxiangli(笑看红尘) 的写法,你可以:
    } finally {
    try {
       if (rs != null) rs.close();
       if (st != null) st.close();
       if (con != null) con.close();
    }
    finally {
    con.close();
    }
     }
      

  5.   

    这下照你这么说,如果con.close()再错误,我可就没办法了,不知大家是否有呢。
      

  6.   

    访问  vvpang(NullPointerException)提供的网页
    决定用以下方法,看看有没有什么弊端?} finally {
      try {
         try {
             if (rs != null) rs.close();
         } finally {
             if (st != null) st.close();
         }
      } finally {
        if (con != null) con.close();
      }
    }