0

I need to install a DDL, preferably saved in a file, into a DB using JDBC. I have seen the addBatch() and executeBatch() methods in 'Statement' API but they seem to require adding individual statements one at a time. I am trying to find a way to add a big bulk of statements (DDL) that I can store in a file and pass as a paramter into a java app that will then use JDBC to install.

gjw80
  • 1,058
  • 4
  • 18
  • 36
  • I think these SO question can help you. http://stackoverflow.com/questions/1497569/how-to-execute-sql-script-file-using-jdbc http://stackoverflow.com/questions/1044194/running-a-sql-script-using-mysql-with-jdbc – Alpesh Gediya May 29 '13 at 17:44

1 Answers1

0

I'm going to give an answer that I think will help you maintainability wise, but it may not be what you're looking for. Here are two libraries that help with database migrations:

  1. http://www.liquibase.org/
  2. http://flywaydb.org/

Not only will these help you execute DDL in a file, they bring lots of other features you don't want to have to reinvent. EG, they'll make sure they only get run once if they succeed.

If these aren't the right tool for the job, I think the comment @Alpesh Gediya made is what you're looking for.

Daniel Kaplan
  • 62,768
  • 50
  • 234
  • 356