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

    Question Multiple Queries using batch Updates

    Can i use multiple Queries in preparesStatement using Batch Updates in SQL
    we can use like this:-

    stmt.addBatch("INSERT INTO COFFEES "
    + "VALUES('Amaretto', 49, 9.99, 0, 0)");
    stmt.addBatch("INSERT INTO COFFEES "
    + "VALUES('Hazelnut', 49, 9.99, 0, 0)");
    --------------------------------------------------------------------------
    but can we use like this (below)??:-

    stmt.addBatch("INSERT INTO COFFEES "
    + "VALUES('Amaretto', 49, 9.99, 0, 0)");
    stmt.addBatch("INSERT INTO COFFEES "
    + "VALUES('Hazelnut', 49, 9.99, 0, 0)");
    stmt.addBatch("INSERT INTO TEA "
    + "VALUES('Amaretto', 49, 9.99, 0, 0)");
    stmt.addBatch("INSERT INTO TEA "
    + "VALUES('Hazelnut', 49, 9.99, 0, 0)");

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

    Default

    Hi,
    U are correct.But,before inserting you should set the autocommit to false.After doing all the above u have to commit.

    -Regards
    Ramya
    Ramya:cool:

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

    Default

    i know we have to set auto commit to false..but my question is dat can we used like dis..

    stmt.addBatch("INSERT INTO COFFEES "
    + "VALUES('Amaretto', 49, 9.99, 0, 0)");
    stmt.addBatch("INSERT INTO COFFEES "
    + "VALUES('Hazelnut', 49, 9.99, 0, 0)");
    stmt.addBatch("INSERT INTO TEA "
    + "VALUES('Amaretto', 49, 9.99, 0, 0)");
    stmt.addBatch("INSERT INTO TEA "
    + "VALUES('Hazelnut', 49, 9.99, 0, 0)");
    :)

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

    Default

    yes u can ...Just write a complete code and try.
    Ramya:cool:

Similar Threads

  1. help me need to understand queries
    By hossainsadd in forum JDBC
    Replies: 1
    Last Post: 05-26-2008, 12:02 AM
  2. queries regarding SWT
    By ravian in forum New To Java
    Replies: 0
    Last Post: 11-26-2007, 03:06 PM
  3. some queries
    By Feng in forum New To Java
    Replies: 7
    Last Post: 11-24-2007, 08:10 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
  •