8.3.42 Notes about the Statement interface
- Organization of this subsection
(1) Notes about executing executeXXX methods
If you execute an executeXXX method before the ResultSet object created by the corresponding Statement object has been closed, the JDBC driver closes the previous ResultSet object that was created. If an attempt is made to use the previously created ResultSet object to acquire retrieval results after the executeXXX method has been executed, the JDBC driver will throw an SQLException. The following shows an example that results in an SQLException.
- ■ Example that results in an SQLException
-
Statement st = con.createStatement(); ResultSet rs1 = st.executeQuery("select * from tb1"); ResultSet rs2 = st.executeQuery("select * from tb2"); rs1.next(); // SQLException is thrown. rs2.next();
(2) Closing the Statement object
After you have used a Statement object, make sure that you close the Statement object explicitly with the close method. When a Statement object is closed explicitly, the corresponding statement handle in HADB is released. If you do not close Statement objects, a shortage of statement handles might occur.
The statement handle is also released when a transaction is settled by issuing COMMIT or ROLLBACK. Therefore, if you settle transactions at appropriate intervals, you can prevent a shortage of statement handles.