views:

45

answers:

2

hi, i am having the script of tables in normal txt files also i have scripts for procedures and functions. Now, i want to just read that file from java and i want op fire that string (script) on DB.. is it possible.. i have written statements for all DML queries, but here i want to use DDL queries from Java.. can any one help me..

+1  A: 

This is question is very similar to what you are asking.

Have also a look at iBatis ScriptRunner.

kgiannakakis
A: 

Read the script with a BufferedReader (see some examples) appending each line to a StringBuilder. Then use JDBC to create Statement and call execute on it, with your stringbuilder object as a string argument.

//create StringBuilder "myProc" here, reading the script
//get Connection conn
//...
Statement stmt = conn.createStatement();
stmt.executeUpdate(myProc);

Check the Java Tutorial lesson on SQL Statements for Creating a Stored Procedure.

You need to handle delimiters and iterate over the script with this idea if your file contains more than one script.

JuanZe