Closing Database Connections in Java

前端 未结 6 1325
小鲜肉
小鲜肉 2020-11-22 09:34

I am getting a little confused, I was reading the below from http://en.wikipedia.org/wiki/Java_Database_Connectivity

Connection conn = DriverManager.getConn         


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 10:14

    It is enough to close just Statement and Connection. There is no need to explicitly close the ResultSet object.

    Java documentation says about java.sql.ResultSet:

    A ResultSet object is automatically closed by the Statement object that generated it when that Statement object is closed, re-executed, or is used to retrieve the next result from a sequence of multiple results.


    Thanks BalusC for comments: "I wouldn't rely on that. Some JDBC drivers fail on that."

提交回复
热议问题