如果ResultSet,Statement不关,直接关Connection是不是默认也将ResultSet和Statement也一起close了?这样处理好不好?不好在哪里? 

解决方案 »

  1.   

    有深度 搜 开发驿站 java 试试 你的选择。前辈说要关闭, 你说你关不关, 不关闭,那close方法有毛用。
    还有借口中说, close是立即关闭, 你直接关闭connection, 就像你只管大门, 不穿内裤一样。
    希望楼主认真考虑, 要不要这么做。
      

  2.   

    关大门不穿内裤,
    楼主还是都关闭了吧,先ResultSet,在Statement,最后con
      

  3.   

    单纯从JAVA API的限制来说,它并没规定Connection的close方法必须关闭附属对象。    /**
         * Releases this <code>Connection</code> object's database and JDBC resources
         * immediately instead of waiting for them to be automatically released.
         * <P>
         * Calling the method <code>close</code> on a <code>Connection</code>
         * object that is already closed is a no-op.
         * <P>
         * It is <b>strongly recommended</b> that an application explicitly 
         * commits or rolls back an active transaction prior to calling the 
         * <code>close</code> method.  If the <code>close</code> method is called
         * and there is an active transaction, the results are implementation-defined.
         * <P>
         * 
         * @exception SQLException SQLException if a database access error occurs 
         */
    根据上面的API,事务在连接关闭时是否回滚都完全取决于实现类,至于其他对象更是没提。
    个人观点,你这样做完全是寄希望于数据库驱动JAR包的作者比较有良心,还是不要偷懒的好。
      

  4.   


    很明显要关闭是因为数据库链接是有连接数上限的,如果用完不关闭,当连接数用完后面的人就连接不上了我说的是直接关闭数据库的连接,但不关闭结果集和Statement
      

  5.   

    还是不是很理解,ResultSet和Statement的连接不是基于Connection的连接么?
      

  6.   

    是否会连带关闭完全取决于Connection的实现类如何操作
    我认为一般是会关闭的,也完全可以做到关闭