Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2013
    Location
    coimbatore
    Posts
    6
    Rep Power
    0

    Default More advisable to closing callableStatement

    Hi,
    I would like to know which callableStatement closing is more advisable and why in below mentioned conditions.

    Condition1:
    CallableStatement callableStatement=null;
    while(iterator.hasNext())
    {
    Vo vo = (VO) iterator.next();
    callableStatement = connection.prepareCall("{call testpac.test(?,?)}");
    callableStatement.setInt(1, roDetailsVO.getId());
    callableStatement.close();
    }

    Condition2:
    CallableStatement callableStatement=null;
    while(iterator.hasNext())
    {
    Vo vo = (VO) iterator.next();
    callableStatement = connection.prepareCall("{call testpac.test(?,?)}");
    callableStatement.setInt(1, roDetailsVO.getId());
    }
    callableStatement.close(); // closing commonly
    Last edited by sasikumarkrishnasamy; 11-16-2013 at 04:35 PM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,856
    Rep Power
    19

    Default Re: More advisable to closing callableStatement

    ...Ignore this bit ...
    Presuming there should actually be an execute call in there between the set and the close, then it has to be first one otherwise you are only closing the last statement.
    However, neither are good as the close should be in a finally block anyway.
    ..............


    ETA: Gah!
    Slow Monday brain.
    Actually you want to prepare the call outside of the loop as you are using the same method call, so reuse the callableStatement.
    Stick the close outside the loop in a finally block.
    Last edited by Tolls; 11-18-2013 at 12:28 PM.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 10
    Last Post: 04-06-2011, 04:45 PM
  2. closing FileOutputStream?
    By mgrootsch in forum New To Java
    Replies: 1
    Last Post: 05-17-2010, 05:36 PM
  3. Problem using CallableStatement
    By jambon in forum JDBC
    Replies: 2
    Last Post: 03-27-2010, 06:02 PM
  4. CallableStatement example
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-10-2008, 11:42 AM
  5. Using CallableStatement
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-22-2007, 11:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •