Closing Resultset and statement
Can any one help on the issue encountered in the following piece of code. It seems that DB connection is lost when trying to execute the query in section 2.
String query = "SELECT .....";
try {
con=getConnection();
String query1 ="SELECT....";
stmt = con.prepareStatement(query1);
rs1 = stmt.executeQuery(query1); -- Section1
while (rs1.next()) {
}
**Close resultset;
Close statement;**
stmt = con.prepareStatement(query); -- Section 2
rs = stmt.executeQuery(query);
I suspec开发者_开发知识库t db connection is lost in section 2. Is this due to the close resultset and statement placed before executing Section2? Please advise.
Regards, Steven
Close the resultset and statement in a finally
block, or at the end of your code.
精彩评论