Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Comparing 2 large ResultSets

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Comparing 2 large ResultSets

    Hi,

    I need to compare 2 large ResultSets (may contain up to 100,000 records each), and output and differences between them. My current code is far too slow (normally around an hour before I terminate it), so I'm wondering if there's a more sophisticated way to do this comparison (perhaps using ArrayLists or HashMaps?) Anyway, here's the code I'm using - any ideas would be really appreciated. Thanks,

    Daniel

    DatabaseA_ResultSet.beforeFirst();
    while (DatabaseA_ResultSet.next()) {

    ComparisonStringA = DatabaseA_ResultSet.getString(1) + "-" + DatabaseA_ResultSet.getString(2);

    foundMatch = "no";

    DatabaseB_ResultSet.beforeFirst();
    while (DatabaseB_ResultSet.next()) {

    ComparisonStringB = DatabaseB_ResultSet.getString(1) + "-" + DatabaseB_ResultSet.getString(2);


    if (ComparisonStringA.equalsIgnoreCase(ComparisonStri ngB)) {
    foundMatch = "yes";
    break;
    }
    }
    if (foundMatch.equalsIgnoreCase("no")){
    System.out.println("didn't find " + ComparisonStringA + " in entire resultSet");
    }
    }


  2. #2
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,103
    Thanks
    169
    Thanked 779 Times in 725 Posts
    Blog Entries
    5

    Default Re: Comparing 2 large ResultSets

    Moved to http://www.javaprogrammingforums.com/jdbc-databases/

    For future reference, please wrap your code in the code tags.

    Use a Set - it allows only unique elements. Place one dataset within, then check whether that set contains values from the second dataset. Or better yet, you could almost surely optimize your query and let the database do this for you (through joins, intersects, minus/except, etc...)

Similar Threads

  1. diplay a large text in JTextArea (>2GB)
    By NeoDesWay in forum AWT / Java Swing
    Replies: 4
    Last Post: August 18th, 2013, 07:20 AM
  2. multiple resultsets
    By kney in forum JDBC & Databases
    Replies: 5
    Last Post: November 28th, 2011, 12:46 PM
  3. My program keeps lagging when dealing with large arrays.
    By chrynelson in forum Java Theory & Questions
    Replies: 4
    Last Post: October 21st, 2011, 04:57 PM
  4. SAAJ giving exception with large attachments
    By Veronica in forum Web Frameworks
    Replies: 2
    Last Post: January 4th, 2011, 03:13 AM
  5. exception while Read very large file > 300 MB
    By ps.ganesh in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: June 11th, 2009, 11:39 PM