Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

??how to compare two resultsets??

843854Dec 21 2004 — edited Dec 23 2004
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 20 2005
Added on Dec 21 2004
7 comments
1,443 views