Posted By:
rick_murphy
Posted On:
Thursday, April 1, 2004 05:59 PM
if a program regist a connection from Database, it must release the connection at last, also, if a program regist a statement from a connection ,it must release it too. For this reason, there will appear code as follow: Connection conn = DriverManager.getConnection("....."); Statement stat = conn.createStatement(); ResultSet rst = stat.executeQuery(sql); //do something with rst rst.close(); stat.close(); conn.close(); many people feel that it's fussy to release connection and statement manually. So, i want to encapsulate the Database operations in a class, the class should have the feature to release the database resource automatical
More>>
if a program regist a connection from Database, it must release the connection at last, also, if a program regist a statement from a connection ,it must release it too. For this reason, there will appear code as follow:
Connection conn = DriverManager.getConnection(".....");
Statement stat = conn.createStatement();
ResultSet rst = stat.executeQuery(sql);
//do something with rst
rst.close();
stat.close();
conn.close();
many people feel that it's fussy to release connection and statement manually. So, i want to encapsulate the Database operations in a class, the class should have the feature to release the database resource automatically.
but
i can not know how long will the ResultSet be used,when i release the statement, the ResultSet was destroyed too.
how can i resolve this problem?
thanks alot!!!
<<Less