Results 1 to 5 of 5
  1. #1
    swati.jyoti is offline Member
    Join Date
    Mar 2009
    Posts
    42
    Rep Power
    0

    Question Same preparedstatement object 4 different queries..

    Can I use like dis since it is not updating all the records..Its only taking the last one..
    Actually i m getting same preparedstatement object for many queries in a loop..In this scenario its not working properly..

    connection con.setAutoCommit(false);
    PreparedStatement prepStmt = con.prepareStatement(
    "UPDATE DEPT SET MGRNO=? WHERE DEPTNO=?");
    prepStmt.setString(1,mgrnum1);
    prepStmt.setString(2,deptnum1);
    prepStmt.addBatch();
    PreparedStatement prepStmt = con.prepareStatement(
    "UPDATE EMP SET EMPNO=? WHERE DEPTNO=?");
    prepStmt.setString(1,empno1);
    prepStmt.setString(2,deptnum2);
    prepStmt.addBatch();

    Whether we can take same preparedstatement object for different query..??Its not giving any error but its not updating all the records but only the last one...

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    832
    Rep Power
    6

    Default

    Hi,
    One small suggestion.
    You are having different queries and statement objects are different.So, for first update u should call executeBatch and second update u should call again executeBatch.or else,like what u said, last statement object query only will get updated.
    Ramya:cool:

  3. #3
    swati.jyoti is offline Member
    Join Date
    Mar 2009
    Posts
    42
    Rep Power
    0

    Default

    Thanks..
    but can u tell me Is that same as individual preparedstatement execution..

  4. #4
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    832
    Rep Power
    6

    Default

    yes.

    Just single statments only know.It will execute normally.
    It is better u do normally removing the batch.
    Ramya:cool:

  5. #5
    swati.jyoti is offline Member
    Join Date
    Mar 2009
    Posts
    42
    Rep Power
    0

Similar Threads

  1. Regarding PreparedStatement
    By adeeb in forum JDBC
    Replies: 0
    Last Post: 06-09-2008, 09:07 PM
  2. Using PreparedStatement
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-22-2007, 11:24 AM
  3. PreparedStatement
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-05-2007, 03:56 PM
  4. calendar object in preparedStatement
    By Heather in forum SWT / JFace
    Replies: 3
    Last Post: 06-30-2007, 02:47 PM
  5. Help me. PreparedStatement
    By Felissa in forum JDBC
    Replies: 2
    Last Post: 06-28-2007, 05:03 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
  •