Originally posted by Lasse Koskela:
I see two ways of doing this.
1) Execute the .sql file using Oracle's command line client (if there is one, that is) and the Runtime.exec() method.
2) Execute the individual statements within the .sql file by reading the .sql file and executing the pieces of SQL using java.sql.Statement. You'll have to do a bit parsing here (for example, semi-colons should be omitted and COMMIT calls should not be executed using Statement).
I agree with Lasse that
you should parse the .SQL file. Just beware of any semi-colons in your data that might cause it to think that it is a delimiter, instead of data. But that should be fairly easy to ensure, since everything is self contained ( not dynamic data ) within the file. The easiest way might be to read the file in to a
String and use the String.split(";") method to break up the individual statements. Then loop the resulting String array, executing each individual sql string.
Jamie