vineetv2821993
vineetv2821993

Reputation: 947

Generate MySQL Query for a Given Result Set in Java

I am having a result set for a particular MySQL Query in Java. What I want to do is to generate the possible query for the generated result set so I can execute those statement to some other database with few modification in the statement. Is there any way i can do that in java?

Upvotes: 1

Views: 143

Answers (1)

BDRSuite
BDRSuite

Reputation: 1612

After reading the comments and your question, it seems that you are trying to create insert queries based on the resultset values that you got and use them for data migration

To create insert statements first you need to have the column types of the table that you are trying to insert into the table as well as the resultset pulled from.

The former you can be easily predicted by viewing the table schema and the latter can be got by functiongetColumnType() using ResultsetMetaData object

So here you go,

  1. Get the columns type along with the resultset data from source database.
  2. Convert the resultset data to the datatype that is equivalent on the database that you are going to migrate.
  3. Create insert statements using the converted values and insert them in the destination database.

This is just a small overview of how the migration process can be achieved. Hope this will provide a basic understanding on how the task can be done.

Upvotes: 1

Related Questions