Link to home
Start Free TrialLog in
Avatar of bhadsock
bhadsock

asked on

Insert a recordset from one MySQL database into another MySQL database with JDBC

I am not sure if this is possible, but I have 2 MySQL database connections and I want to take a recordset from one database and insert it into the other database connection without having to go through the recordset row by row and column by column.

Is it possible to insert a complete recordset with one statement?
Avatar of erikjensen
erikjensen

Sorry there is no way to insert a complete recordset with one statement the only way is row by row.

I am not familiar with MySQL, is there not some way to write a script in MySQL to do the job?
Avatar of bhadsock

ASKER

In MySQL, you can create an SQL statement that will insert data from a SELECT statement from another database.  Below is the the SQL statement I used when both databases lived on the same server:

INSERT INTO Database1Name.TableName SELECT * FROM Database2Name.TableName WHERE Database2Name.TableName.FieldName = 'SomeCriteria'

But now, the 2 databases are on 2 different database servers and therefore 2 different JDBC connections and each database is not aware of the other.

Is there a way to execute a similar SQL statement to the one I used above across 2 database connections?
ASKER CERTIFIED SOLUTION
Avatar of erikjensen
erikjensen

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of girionis
No comment has been added lately, so it's time to clean up this TA.

I will leave a recommendation in the Cleanup topic area that this question is:

- points to erikjensen

Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

girionis
Cleanup Volunteer