Results 1 to 4 of 4
  1. #1
    Arun_N is offline Member
    Join Date
    May 2011
    Posts
    21
    Rep Power
    0

    Smile is it possible to execute 3-4 prepated statements at once as batch?

    Ex:-
    PreparedStatement pstmt = conn.prepareStatement(INSERT_RECORD);
    pstmt.setString(1, "1");
    pstmt.setString(2, "name1");
    pstmt.addBatch();
    pstmt = conn.prepareStatement(DELETE_RECORD);
    pstmt.setString(1, "5");
    pstmt.addBatch();//is it possible?
    int[] i = pstmt.executeBatch();//is it possible?

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default Re: is it possible to execute 3-4 prepated statements at once as batch?

    Well, seeing as how you are redefining the variable and so pstmt after the second prepareStatement no longer refers to the same object as it did before that, what do you think?

  3. #3
    Arun_N is offline Member
    Join Date
    May 2011
    Posts
    21
    Rep Power
    0

    Default Re: is it possible to execute 3-4 prepated statements at once as batch?

    yes , even i got the same doubt, if i want to execute all statements at once is it possible? any other way?

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default Re: is it possible to execute 3-4 prepated statements at once as batch?

    It is not a "doubt", it is a certainty.

    You can't, but what you are really looking for, I believe, is doing them as a single transaction. IOW, connection.setAutoCommit(false); statement; statement; statement; conn.commit();

Similar Threads

  1. Replies: 3
    Last Post: 07-07-2011, 07:20 AM
  2. Replies: 1
    Last Post: 07-06-2011, 10:19 PM
  3. Batch RSA
    By Nita Jackson in forum Advanced Java
    Replies: 0
    Last Post: 02-15-2011, 06:24 AM
  4. Replies: 0
    Last Post: 04-01-2008, 11:41 AM
  5. Replies: 0
    Last Post: 09-28-2007, 01:59 PM

Posting Permissions

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