0

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..

Wim Coenen
  • 66,094
  • 13
  • 157
  • 251
M.J.
  • 16,266
  • 28
  • 75
  • 97

2 Answers2

1

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

Have also a look at iBatis ScriptRunner.

Community
  • 1
  • 1
kgiannakakis
  • 103,016
  • 27
  • 158
  • 194
0

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
  • 8,007
  • 44
  • 58