| | |
JDBC compare the content of two tables
![]() |
•
•
Join Date: Nov 2004
Posts: 189
Reputation:
Solved Threads: 0
Hello everyone,
I am using JDBC to compare the content of two database tables -- writing a general function and two tables are input. The two tables have various types of columns, like VARCHAR, BLOB, INT, FLOAT, etc.
I want to save my time to write various statements to get values by different types and compare them, for example, for VARCHAR, I need to use getString and compare the content by String compare function, and for INT column, I need to use getInt and compare with Integer compare function.
I am wondering whether there are any smart way to implement in an uniformed way so that I do not need to write various switches according to column type.
thanks in advance,
George
I am using JDBC to compare the content of two database tables -- writing a general function and two tables are input. The two tables have various types of columns, like VARCHAR, BLOB, INT, FLOAT, etc.
I want to save my time to write various statements to get values by different types and compare them, for example, for VARCHAR, I need to use getString and compare the content by String compare function, and for INT column, I need to use getInt and compare with Integer compare function.
I am wondering whether there are any smart way to implement in an uniformed way so that I do not need to write various switches according to column type.
thanks in advance,
George
Yes and no...
Several things come to mind.
An enum with a lookup method by column type that returns a handler for that column type is the most obvious.
Use a Map of column type names to enum instances for that.
Several things come to mind.
An enum with a lookup method by column type that returns a handler for that column type is the most obvious.
Use a Map of column type names to enum instances for that.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
•
•
Join Date: Nov 2004
Posts: 189
Reputation:
Solved Threads: 0
Thanks jwenting,
I am not going to compare the column types, but content of table -- rows.
The two tables are of the same schema -- same column names and column type.
I am interested in your above method. But I still need to program differently for different column types to write equals (or compareTo) method, right?
Are there any ways to implement in an unified coding way independent of column types?
regards,
George
I am not going to compare the column types, but content of table -- rows.
•
•
•
•
Yes and no...
Several things come to mind.
An enum with a lookup method by column type that returns a handler for that column type is the most obvious.
Use a Map of column type names to enum instances for that.
I am interested in your above method. But I still need to program differently for different column types to write equals (or compareTo) method, right?
Are there any ways to implement in an unified coding way independent of column types?
regards,
George
Edit: Nevermind, silly me, thinking of something completely different.
Last edited by masijade; Aug 10th, 2007 at 8:29 am.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
•
•
I am interested in your above method. But I still need to program differently for different column types to write equals (or compareTo) method, right?
Last edited by ~s.o.s~; Aug 11th, 2007 at 2:33 pm. Reason: Fixed the quote tags.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
•
•
Join Date: Nov 2004
Posts: 189
Reputation:
Solved Threads: 0
Thanks jwenting,
I want to use getObject method to get the value of each column,
then use equals method of java.lang.Object to compare two columns' values. Is that method workable?
I have a quick question, I think if I use getObject to get a column value
from a table, for example, an Integer column, then when using equals method to compare, I think I am using equals method from java.lang.Integer, other than java.lang.Object, right?
Object int_column_value1 = getObject (...);
Object int_column_value2 = getObject (...);
// to check
int_column_value1.equals (int_column_value2);
regards,
George
•
•
•
•
the JDBC API has several options that may work.
getBytes(int) and getObject(int) on ResultSet come to mind.
then use equals method of java.lang.Object to compare two columns' values. Is that method workable?
I have a quick question, I think if I use getObject to get a column value
from a table, for example, an Integer column, then when using equals method to compare, I think I am using equals method from java.lang.Integer, other than java.lang.Object, right?
Object int_column_value1 = getObject (...);
Object int_column_value2 = getObject (...);
// to check
int_column_value1.equals (int_column_value2);
regards,
George
![]() |
Similar Threads
- copying string from a vector to another (C++)
- HTML parsing by perl (Perl)
- Help connecting to mysql tables (JSP)
- hi.. string compare (Java)
- adjacent tables split up with content (HTML and CSS)
- compare 2 xml files with csharp (C#)
- Fixed table headers problem .. (HTML and CSS)
- Page Loading (JavaScript / DHTML / AJAX)
- Compare two tables (MS SQL)
- updating 2 HTML tables on one PHP page (PHP)
Other Threads in the Java Forum
- Previous Thread: Installing Jconnector for MySql Server
- Next Thread: illegal start of expression & type
| Thread Tools | Search this Thread |
2dgraphics account android api apple applet application arguments array arrays automation banking binary binarytree bluetooth chat chatprogramusingobjects class client code color component count database derby design eclipse eclipsedevelopment encryption error fractal game givemetehcodez graphics gridlayout gui homework html ide if_statement image integer interface j2me java javadesktopapplications javaprojects jlabel jni jpanel jtextfield julia keyword linux list macintosh map method methods midlethttpconnection mobile netbeans newbie nullpointerexception object open-source os problem producer program programming project projectideas property read recursion reference replaysolutions ria scanner search server set size sms sort sourcelabs splash sql sqlite stop string swing threads transforms tree ui unicode validation windows






