Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / August 2006

Tip: Looking for answers? Try searching our database.

Moving tables contents between databases using JDBC

Thread view: 
Rafal Solinski - 06 Aug 2006 17:49 GMT
Hi,

I'm working on a simple program, which migrates tables between
different databases. Assuming that table schemas are exactly
the same (from JDBC point of view - using DatabaseMetaData class
I can check tables schemas) how I can move rows between
databases, without knowing each column type? I just want to
get an object representing for example second column and
insert it into the others table second row. Of course one could
analyse the column type, convert it to String and build
INSERT INTO ... sql instruction, but I am hoping for a simplier
solution.

Regards, Rafal
Thomas Kellerer - 06 Aug 2006 21:15 GMT
Rafal Solinski wrote on 06.08.2006 18:51:
> Hi,
>
[quoted text clipped - 8 lines]
> INSERT INTO ... sql instruction, but I am hoping for a simplier
> solution.

Do a SELECT on the source, then use a PreparedStatement for the INSERT on the
target. The use getObject() on the ResultSet you obtain from the source, and do
a setObject() for each column on the target INSERT. But be aware that some
drivers do not correctly implement getObject() and it is not guaranteed that the
Object returned by the driver from the source DB will return a class that the
driver from the target can handle.

But there are OpenSource solutions at sourceforge (don't know the name right
now) which have already solved those problems...

Regards
Thomas
Tom Cole - 15 Aug 2006 18:09 GMT
Create a CASE statement using the DATA_TYPE value returned in the
getColumns method of DatabaseMetaData. The int in the DATA_TYPE value
of the resulting ResultSet maps to a java.sql.Types value. Use it in
the case to know which setXxx method to call.

> Rafal Solinski wrote on 06.08.2006 18:51:
> > Hi,
[quoted text clipped - 22 lines]
> Regards
> Thomas


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.