Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By Tolls

Thread: How to find multiple inset into database success?

  1. #1
    athar is offline Member
    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0

    Default How to find multiple inset into database success?

    Hi
    I want to know whether multiple rows insertion is success or not? for single am using int iSuccess = stmt.executeUpdate(); How to know whether multiple insert is success?
    Thanks

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

    Default Re: How to find multiple inset into database success?

    Are you talking a batch job with multiple insert statements?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    athar is offline Member
    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0

    Default Re: How to find multiple inset into database success?

    Hi
    No, i have data in List and loop through this list and insert record into database. Here is my code

    String qString = "INSERT INTO Estd_Contents( file_ref, a,b ) values (?,?,?)";
    PreparedStatement stmt = conSqlServer.prepareStatement(qString);
    for(int i = 0; i < lstAllContents.size(); i++)
    {
    stmt.setString(1, lstAllContents.get(i).getFileRef());
    stmt.setDouble(2, lstAllContents.get(i).getNetAmt());
    stmt.setString(3, lstAllContents.get(i).getAcctNo());
    stmt.executeUpdate();
    }
    conSqlServer.commit();
    System.out.println("Contents inserted successfully!");

    Maximum 3500 records i will insert at a time.

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

    Default Re: How to find multiple inset into database success?

    Batch them, for starters.
    Doing single inserts like that is not terribly good performance-wise.
    Java Code:
    for(int i = 0; i < lstAllContents.size(); i++)
    {
       stmt.setString(1, lstAllContents.get(i).getFileRef());
       stmt.setDouble(2, lstAllContents.get(i).getNetAmt());
       stmt.setString(3, lstAllContents.get(i).getAcctNo());
       stmt.addBatch();
    }
    int[] results = stmt.executeBatch();
    Then you will be able to see how many succeeded, and which ones (depending on db).
    athar likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    athar is offline Member
    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0

    Default Re: How to find multiple inset into database success?

    Thanks Tolls
    it worked. Before it was taking 4 seconds to insert 3500 records and now less than 1 sec

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

    Default Re: How to find multiple inset into database success?

    That's because before you were doing the round trip to the database 3500 times, with all the overhead that entails.
    Now you're doing it once.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Problem in my OCJP success kit.
    By makpandian in forum Java Certification
    Replies: 0
    Last Post: 08-26-2011, 01:56 PM
  2. Using Linear Search to find multiple indexes
    By Roberto1989 in forum New To Java
    Replies: 1
    Last Post: 03-16-2011, 04:36 PM
  3. Accessing multiple database
    By saurabh1989 in forum JDBC
    Replies: 0
    Last Post: 02-23-2011, 05:04 PM
  4. Hibernate with multiple database
    By Marty in forum JDBC
    Replies: 3
    Last Post: 12-23-2008, 12:57 PM
  5. How to store Multiple calendars in PIM Database
    By thirupathik in forum CDC and Personal Profile
    Replies: 0
    Last Post: 07-13-2008, 01:45 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
  •