Comparing two ResultSet

Hi Everybody,
Can anybody tell me is there any method to compare the contents of two ResultSets and decide whether they are same or not.
Thanks

Yes,
Create a method that takes the two result sets, get the metada of the table and compare field by fiel.
Another alternative is to copy the ResultSet to a Vector and than compare it.
HTH
Trajano Roberto

Similar Messages

  • ??how to compare two resultsets??

    hi all!
    i need to find out whether two resultsets contain the same data.
    the only way i know how to do it in java is to put them into a while loop and fetch the contents first and then compare the contents.
    but is there an easier way to compare resultsets?
    does anyone know how to compare two resultsets without extracting the data?
    the code example here executes two identical queries on an oracle database, compare and print the resultsets.
    public ResultSet getResultset(String query)
    ResultSet rs=null;
    try { rs=Stmt.executeQuery(query); }
    catch(Exception e) { e.printStackTrace(); }
    return rs;
    public static void main(String[] args) {
    ResultSet r1=null;
    ResultSet r2=null;
    try {
    database db = new ddatabase();
    r1=db.getResultset("Select 'name' from person");
    r2=db.getResultset("Select 'name' from person");
    if (r1 == r2) {
    System.out.println("ok");
    System.out.print(r1);
    System.out.println();
    System.out.print(r2);
    else {
    System.out.println("not ok");
    System.out.print(r1);
    System.out.println();
    System.out.print(r2);
    jdbc.cleanup();
    catch(Exception e) {e.printStackTrace();}
    and here is the output:
    F:\java rs_compare
    not ok
    oracle.jdbc.driver.OracleResultSetImpl@4413ee
    oracle.jdbc.driver.OracleResultSetImpl@786e64
    as you can see the resultsets are different though the data they contain have to be the same.
    so the 'if(resultset#1 == resultset#2)' does not work.
    thanks for any help
    best regards
    5ithl0rd

    Don't cross-post.
    I'll bet ResultSet implementations don't override equals() to provide "deep equals" behavior, in which case it'll be no different than using "==".
    It's a bad idea to compare two ResultSets this way. You'll have to load both into objects or data structures and compare those in a "deep" way.
    Besides, the ONLY way two ResultSets could be different, given the same query, would be if there were multiple clients that could write to the table between queries and change the underlying data. If your two queries are sufficiently isolated, I'd say that the same query will return the same ResultSet.
    %

  • Comparing two ResultSets for equality

    Hello,
    I wish to test if two separate ResultSet objects are identical.
    By identical I mean that two different ResultSet objects are identical if
    they contain the same rows in the same order, and each row contains identical values in the two ResultSets.
    Two possibilities could be that the equals() method returns true or that the hashcode() method also produces the same hash value if the objects are identical as described.
    I haven't been able to find any documentation on this issue.
    Does anyone know if either (or both) of these methods have the contract as described above? If so are they guaranteed?
    I can see several potential problems here. Performance with a large ResultSet, duplicate rows, and the ordering of rows not being guaranteed?
    Thanks in advance.
    Tim

    Two possibilities could be that the equals() method
    returns true or that the hashcode() method also
    produces the same hash value if the objects are
    identical as described.I can tell you without looking anything up that these methods do not do that, as doing that would require them to scan the entire result-set, and JDBC tries to avoid doing useless processing. You are going to have to write this code yourself.

  • Two resultset objects

    IS it possible to define two resultset objects with two different queries inside the same DB class?java.sql.SQLException: Invalid state, the ResultSet object is closed.
         at net.sourceforge.jtds.jdbc.JtdsResultSet.checkOpen(JtdsResultSet.java:299)
         at net.sourceforge.jtds.jdbc.MSCursorResultSet.next(MSCursorResultSet.java:1123)
         at DB5.getDetails(Daily_Quote_Response_report.java:238)
         at Daily_Quote_Response_report.main(Daily_Quote_Response_report.java:74)
    java.util.List items = null;
            String query;
            String query2;
            try {
                query =
                       "select * from oqrep_except_resp_summary";
                query2 = "select * from oqrep_except_resp_detail";
                Statement state = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                        ResultSet.CONCUR_READ_ONLY);
                ResultSet rs = state.executeQuery(query);
                ResultSet rs2 = state.executeQuery(query2);
              //cannot create two rs objects // ResultSet rs2 = state.executeQuery(query);
                items = new ArrayList();Edited by: bobz on 03-Dec-2009 11:16
    Edited by: bobz on 03-Dec-2009 11:16

    Note: This thread was originally posted in the [Java Programming|http://forums.sun.com/forum.jspa?forumID=31] forum, but moved to this forum for closer topic alignment.

  • Compare two similar objects

    Do you know about any possible Java bugs with JDK update?
    In my case, my code stopped working.
    Here is what I have. There are two similar objects, but Object 1 has key, and Object 2 (same as Object 1) has no key. I need to compare both, and if they are equal, I need Object 1 to assign key to Object 2.
    It worked before. How I can get around.
    Please help me if you can.
    Respectfully,
    Alex

    Let me change the question:
    "Can we compare two objects one with key and another one without key? How?

  • Compare two Java Objects without Comparable / Comparator

    Hi Friends,
    I would like to compare two java objects (lots o attributes) without using Comparable / Comparator.
    Any suggestion/sample code would be helpful.
    Thanks,
    Sachin

    I suppose you could design another feature to compare Objects... but that would involve a design process, so asking for sample code is definitely premature. And as EJP says, what would be the point?
    At least that's what I would answer if this was one of those stupid interview questions.

  • Controversy in two ResultSet!!!

    Could anyone please provide me a solution for this problem..
    I've created two ResultSet rs1 and rs2, both are retrieving the data from the same table. Manipulation of rs2 or any kind of processing should affect the rs1. So, if i updating something in the same table through rs2 , so it should affect the entire table . So, for other retrieval of data it should be updated. I've written this code, but it's not working.....
    Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
                    ResultSet rs,rs1;
                    rs=stmt.executeQuery("select * from checkdata");
                    while(rs.next())
                        String s1=rs.getString(1);
                        int count=1;
                        rs1=stmt.executeQuery("select phone_no from checkdata where phone_no='"+s1+"'");
                        while(rs1.next())
                            if(!(rs1.isLast()))
                                count=count+1;
                                rs1.deleteRow();
                            stmt.executeUpdate("update checkdata set count='"+count+"' where phone_no='"+s1+"'");Please help me out!!!!
    in advance thanks a lot....

    First of all i've this sample_log.txt file which i've putted into the table using bulk insert command . The text file looks like:
    123:books:java:Tue Dec 24 10:34:56 IST 2006
    123:books:java:Wed Dec 25 16:45:58 IST 2006
    123:books:java:Fri Dec 27 10:34:12 IST 2006
    234:books:C++:Mon Mar ..............................
    etc. it's a log file so it just added into the text as the request comes.
    Now i've putted all these values into the table.
    What i want is to read all these details and update the details as the last accessed. Suppose in this example, there should be only one entry for '123' and also update the details as the latest time that is 'Fri Dec 27 10:34:12 IST 2006' rest the two(2) should be deleted from the database and also there should be one more coloumn name count which is to be incremented as it encountered the same no. i.e '123' else it should be 1. The result i want is:
    after putting the logic it should appear as:
    123:books:java:Fri Dec 27 10:34:12 IST 2006:3
    234:books:c++:Mon Mar 12 10:12:10 IST 2006:1
    etc......
    I've to do all this in my jsp page using jdbc connectivity, with SQL 2005 as database.

  • How can I compare two collections at the same time? (View two grid views)

    I have two collections containing some of the same images. (My Nikon D70 did not put an end-of-file on some images. I recovered them into a different collection.) Now I want to display both collections side-by-side in grid view. I will select those images in the "recovered" collection that correspond to the bad images in the "main" collection, add the ratings etc, and move just these to another collection.
    It is extremely frustrating to have to bounce back and forth between collections, remembering each image one by one and selecting it in the "recovered" collection. (The image names are not preserved in the "recovered" collection -- I have to go by what the image looks like.)
    LightRoom allows me to compare photos in the compare view. I want to compare collections in two grid views.

    CaptureTheLight,
    you have ran into a situation when you have to compare two sets of images and now you're wondering how come Lightroom doesn't have such "obviously necessary" functionality? But you have to admit it, this is not such a common situation in a photographer's workflow recovers broken files and tries to compare them against themselves. I think it's a pretty specific feature you need. Still, Lightroom has enough powerful tools for editing and sorting images.
    For example...
    You could just put them all - "main" and "recovered" - into a single collection or into the Quick Collection. Label the entire "recovered" collection with, say, red and sort by capture time. Now you'll have everything side by side, ordered chronologically. The "recovered" images will stay next to the "main" images since their capture time will be the same, and they will also stand out since they have the red label.
    Make the thumbnails bigger and set up the grid view so it tints the thumbnail cell are tinted with the label color. Now, you can go quickly through them visually checking labeled vs unlabeled.

  • How can i compare two excel files with different no. of records.

    Hi
    I am on to a small project that involves us to compare two excel files. i am able to do it but am struck up at a point. When i compare 2 different .csv files with different no. of lines i am only able to compare upto a point till when the number of lines is same in both the files.
    Eg. if source file has 8 lines and target file has 12 lines. The difference is displayed only till 8 lines and the remaining 4 lines in source lines are not shown.
    Can you help me in displaying those extra 4 lines in source file. I am attaching my code snippet below..
    while (((strLine = br.readLine()) != null) && ((strLine1 = br1.readLine())) != null)
                     String delims = "[;,\t,,,|]";
                    String[] tokens = strLine.split(delims);
                    String[] tokens1 = strLine1.split(delims);
                   if (tokens.length > tokens1.length)
                    for (int i = 0; i < tokens.length; i++) {
                        try {
                            if (!tokens.equals(tokens1[i])) {
    System.out.println(tokens[i] + "<----->" + tokens1[i]);
    out.write(sno + " \t" + lineNo1 + " \t\t" + tokens[i] + "\t\t\t\t" + tokens1[i]);
    out.println();
    sno++;
    } catch (Exception exception)
    out.write(sno + " \t" + lineNo1 + " \t\t" + tokens[i] + "\t\t\t\t" + "");
    out.println();
    Thanks & Regards                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    A CSV file is not an Excel file.
    But apart from that your logic makes no sense.
    If the 2 files are of different sizes the files are different by definition, so further comparison isn't needed, you're done.
    If you want to compare individual records, you need to compare all records from one file with all records from the other, unless the order of records is important in which case your current system might work.
    That system however is overly complicated for comparing CSV files.
    As you assume a single record per line, and if one can assume those records to have identical layout (so no leading or trailing whitespace in or between columns in one file that's not in the other) comparing records is simply a matter of comparing the entire lines.

  • Functinality to compare two material price with reference to BOM in CO

    Hi All,
    Is there is any functionality in Controlling which can compare the costing for two FERT materials.
    or
    is there is  any functionality where we can compare two material price with reference to BOM in controlling
    Please help me to compare the material price with reference to BOM
    Regards
    nandu

    Hi,
    You can use this report to compare two itemizations. The report compares the characteristics item number, item category, cost element, resource, material, cost center, plant/work center, cost center/activity type, operation number, BOM item, assembly indicator, and cost component.
    You can access this report as follows:
    Accounting ® Controlling ® Product Cost Controlling ® Product Cost Planning ® Material Costing ® Cost Estimate with Quantity Structure or Cost Estimate Without Quantity Structure ® Compare
    or
    Accounting ® Controlling ® Product Cost Controlling ® Product Cost Planning ® Information System ® Object Comparisons ® For Material ® Itemization Comparison.
    For Detail Please reffer following link:
    http://help.sap.com/saphelp_46c/helpdata/en/56/abd108f1a611d28a950000e8214595/content.htm
    Thanks and Regards
    Binoj M D

  • Compare two input text in adf

    Hi
    i used the Build JDEVADF_11.1.1.4.0
    I want to make compare  validation between two  input text  Are equal or not . same Thing when i create new email i must enter the password and re enter password if not   equal  he give me message

    Hi,
    for a validation String, you can put autosubmit=true and in the valuechangeListener make the comparation.
    How to compare two Strings in java? http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java

  • How to compare two excel reports and find the difference in BI Publisher

    Hi All,
    I have a requirement that needs to compare two excel reports in XML Publisher 5.6.2. or BI publisher 10.1.3.4
    If anybody has an idea about this pls help us.
    Thanks,

    Since our customer wants to have this comparison only with BI reports....here is the scenario how the comparison should be..
    Now,we have a parameters called Customer name and version id. Version id list will be refreshed based on the customer selection.
    User can generate the report based on the selected customer name and version id. These data are fetch from the oracle database and we are using Data Template in the BI Publisher.
    Now the requirement is customer wants to compare two version id data. for example, v1.2 and v1.3
    Now they wanna to see both the reports while generating in the same work sheet, like, v1.2report should display in the left side and the v1.3report has to display in the right hand side of the same work sheet.
    Now...If there is any addition happened in v1.3 report,then that cell/data should display as a green color in that report.
    If any deletion happened in v1.3report then that should be in the red color.
    If any modification happened in v1.3 then that should be in the yellow color.
    If there is no difference then that should display as it is.
    the thing is that, the both the reports (v1.2 and v1.3)should display side by side in the same worksheet with the format and everything........only the difference should be highlighted.
    Template is same for both the reports..
    To display the data for both versions i think i can generate the template side by side of both in the same worksheet.
    Now, My question is how to find the difference of data in the RTF Template for both the versions
    Can anybody assist me?
    Thanks,
    Edited by: user753355 on Jun 9, 2009 12:03 AM
    Edited by: user753355 on Jun 9, 2009 12:06 AM
    Edited by: user753355 on Jun 9, 2009 12:16 AM
    Edited by: user753355 on Jun 10, 2009 3:59 AM

  • Compare two pdf files using adobe acrobat through command line

    Does anyone know how to compare two pdf files using adobe acrobat through command line. I want to do this via command line because we want to compare hundreds of file every day through some automated windows tasks.
    If command line option is not available in acrobat, then is it feasible to make use of acrobat javascript API to do this task?
    Any kind of help will be greatly.

    Command-line: Not possible.
    JavaScript: Possible, but very limited. Basically the only thing you can do is simulate clicking the Compare Documents button. The rest has to be done manually.
    However, it *might* be possible to automate this process a bit more using a plugin. Ask over at the Acrobat SDK forum for more information...

  • How to change the color of letters instead of highlight the text when compare two documents

    Hello!!
    I have the Adobe Acrobat 9 Pro (Versión 9.0.0) and I need to compare two documents, but I want to show the diferences changing  the color of letters instead of highlight the text with any color. My boss tell me that other Acrobat version have this option, but I couldn't find it in this version.
    Could you help me on this topic??
    Thanks

    Hello!!
    I have the Adobe Acrobat 9 Pro (Versión 9.0.0) and I need to compare two documents, but I want to show the diferences changing  the color of letters instead of highlight the text with any color. My boss tell me that other Acrobat version have this option, but I couldn't find it in this version.
    Could you help me on this topic??
    Thanks

  • How to compare two excel files in java ?

    how do i compare two excel files in java.?
    I have two excel files stored on my computer in d: drive.
    Ex:
    D:\\file a
    D:\\file b
    How to compare the contents of these two files and print " files are equal " or "files not equal "

    Javamastermahe wrote:
    I mean i want to print on the console "files are equal " or any message like " both the files match "If this is your requirement, this program satisfies it...
    import java.util.Random;
    public class SuperExcelTester {
        public static void main(String[] args) {
            Random rnd = new Random();
            String[] messages = {
                "files are equal",
                "files are not equal",
                "unexpected error"
            int index = rnd.nextInt(messages.length);
            System.out.println(messages[index]);
    }

Maybe you are looking for