开发者

creating procedure/tables from java files

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.. c开发者_如何学Goan any one help me..


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

Have also a look at iBatis ScriptRunner.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜