Would there be any effect if I close my Connection object once I got my ResultSet?
Connection con= DriverManager.getConnection();
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(query);
con.close();
Further to this I use my rs object and I feel there will not be any impact on it. Because ResultSet and Statement are in connection with each other.
You can't access the resultset soon after you close the connection to the database. Because, when you use resultset.next() method, it will send a request to the database in order to fetch the next record; but physically the connection has been closed. So, an Exception will be thrown by your statement resultset.next().
Once the Connection is closed other resources (Statements or ResultSets) must not be used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With