Home > OS >  How to create table from sql file with JPA or JDBC?
How to create table from sql file with JPA or JDBC?

Time:12-15

I am new with java. I want to create a table with my SQL file on application start up beside JPA entity auto generate.

Please you advise me, how can I do that. Thank you

CodePudding user response:

This answer is more of a blueprint, as you did not specify your exact underlying SQL database. One approach I find workable here is to first start up your Java application and let JPA setup and configure all tables. Then, using the tables which already exist, find some way to dump the DDL for that table to a file. For example, on MySQL you could run SHOW CREATE TABLE yourTable to generate the DDL for creating that table.

If you need to do this for all tables, your database may have a tool for capturing the DDL for the entire database at once.

CodePudding user response:

Most convenient way to use database migrations, e.g. flyway

  • Related