开发者

Closing Resultset and statement

开发者 https://www.devze.com 2023-03-30 08:38 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消