Wouter Oet wrote:I'm not familiar with GWT but doesn't it have a number-only-textbox or something similar? You can always use Integer.parseInt()
Martin Vajsar wrote:Ashu,
first of all, please restate your goal. The code I've written searches for rows that exist only in the first, only in the second or in both resultsets, processing all rows from both resultsets. This is what I understand by "comparing resultsets". If you only want to see whether a single row from one resultset is present in the other one, please see my first response.
Secondly - if you want to create a generic solution, that will be lots and lots of work. I've assumed that the column names and types are known. Since I've never need to process a resultset generically, I can't really effectively help you with this approach. If you want some help from me, please start with a non-generic example, where the query is known and the resultset contains a known set of columns of various types. I can help you make such example work, but to turn it into generic algorithm will be then up to you.
And lastly, you didn't follow the template I've already given you. The logic in your solution will not work. See how I have arranged calls to the resultsets' next() methods and try to figure out why is this so.
[/Hi Martin,
I wanted this class as I had to migrate rows from one DBMS to other DBMS. The first one is Oracle 10G and the otherone is Oracle 11G. Befrore I migrate rows I need to check if the rows already exist in the new DBMS or not. We are moving to 11G but we are using both 10G and 11G for inserting app data for some time.
Now, number of columns in 11G may be equal or more than 10G.
]
Ravi Kiran Va wrote:Hi Ashu Bharadwaj , rather than comparing the ResultSet directly , What you can do is take the ResultSet data into ArrayList and compare both the ArrayLists .
[Thanks Ravi, could you please tell me the advantages that I will have in using ArraLists. Please let me know more about the implementation.
Thanks]
Martin Vajsar wrote:
Ashu Bharadwaj wrote:
Could you please provide me pseudocode for iterating through records. The resultset is not too large, so we can iterate through the records.
Very briefly:
The compareRS method compares values of columns that were used in the ORDER BY clause of the two recordsets in order in which they were specified. If the values in the first column are equal, compare values of the second one, till all columns are compared or a difference is found. The returning value should follow the standard Java convention.
The comparison must be done identically with the database. If your data may contain null values, handle them as the database does (ORDER BY usually allows to specify NULLS FIRST or NULLS LAST, if not, determine the convention of your database and use it). If you process strings that may contain international characters, the best bet is to use non-lexicographical ordering in the database. It is usually the default, however it might also be affected by database connection/session settings.
Martin Vajsar wrote:
Ashu Bharadwaj wrote:
Could you please provide me pseudocode for iterating through records. The resultset is not too large, so we can iterate through the records.
Very briefly:
The compareRS method compares values of columns that were used in the ORDER BY clause of the two recordsets in order in which they were specified. If the values in the first column are equal, compare values of the second one, till all columns are compared or a difference is found. The returning value should follow the standard Java convention.
The comparison must be done identically with the database. If your data may contain null values, handle them as the database does (ORDER BY usually allows to specify NULLS FIRST or NULLS LAST, if not, determine the convention of your database and use it). If you process strings that may contain international characters, the best bet is to use non-lexicographical ordering in the database. It is usually the default, however it might also be affected by database connection/session settings.
Martin Vajsar wrote:What you describe is a way to locate any record in a resultset based on column values. Short of iterating through all records and comparing the column values searching for the match I don't see another solution. However, I'd probably run a query searching just for the desired column values. Much better than bringing all of the table from the database to the client and iterating through it.
However, using either of the above to really compare two resultsets (ie. repeating the search for every record in another resultset) would be grossly inefficient, especially with large resultsets. It is really a bad idea.
The best way to compare resultsets, in my opinion, is to sort both ResultSets (using ORDER BY clause) by the same criteria, ideally by a primary key, if it is the same in both tables, or by all of the common columns of the two queries. Then it is possible to identify identical and missing records in one pass over the contents of the two resultsets (you'll go to next record in the resultset that contains the "lesser" of the two records, if the two records are equal, you'll go to next record in both resultsets).
Another way would be to bring the two databases together (eg. using a database link, if your database supports one) and doing all of the work using MINUS and UNION operators. This would be much less code to write, however the database links bring up some administration overhead.
Campbell Ritchie wrote:Is your problem with the Timestamp#toString() method, or do you wish to change the date to show 00:00:00.00 as the time Do you need to set hours minutes and seconds to 0 on the Calendar object before passing it to the Timestamp?
And which TimeStamp do you mean?There is no TimeStamp in the Oracle API but there are two Timestamp classes.