Results 1 to 2 of 2

Thread: compare speed

  1. #1
    bbq
    bbq is offline Senior Member
    Join Date
    Jun 2007
    Posts
    132
    Rep Power
    0

    Default compare speed

    I want to choose the fastest:

    Java Code:
    1. PreparedStatement stmt = con.prepareStatement(
    "INSERT INTO pupils VALUES (?, ?)");
    stmt.setInt(1, 1000);
    stmt.setString(2, "Edward Brown");
    stmt.addBatch();
    
    stmt.setInt(1, 3000);
    stmt.setString(2, "Beto Fri");
    stmt.addBatch();
    
    // submit the batch for execution
    int[] updateCounts = stmt.executeBatch();
    2.
    Java Code:
    PreparedStatement stmt = con.prepareStatement(
    "INSERT INTO pupils VALUES (?, ?)");
    
    stmt.setInt(1, 1000);
    stmt.setString(2, "Edward Brown");
    stmt.executeUpdate();
    
    stmt.setInt(1, 3000);
    stmt.setString(2, "Beto Fri");
    stmt.executeUpdate();
    which one is fast for execution and why?

  2. #2
    Revelation is offline Member
    Join Date
    Jun 2007
    Posts
    6
    Rep Power
    0

    Default

    well, probably the first because you are adding values to a batch queue and then executing the batch job. Depending on how much more efficient the batch processor is than executing multiple instances of the update command separately which likely has a lot more overhead.

Similar Threads

  1. How to Compare two Dates
    By Java Tip in forum java.util
    Replies: 1
    Last Post: 06-24-2008, 08:05 AM
  2. Compare 5 numbers
    By Snowboardmylife in forum New To Java
    Replies: 5
    Last Post: 04-15-2008, 08:04 PM
  3. Compare lists
    By JavaNoob in forum New To Java
    Replies: 2
    Last Post: 08-08-2007, 04:11 PM
  4. how to compare two strings
    By elizabeth in forum New To Java
    Replies: 7
    Last Post: 08-06-2007, 04:57 AM
  5. Compare 2 XML
    By Peter in forum XML
    Replies: 1
    Last Post: 07-05-2007, 03:58 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
  •