2010-01-04 43 views
0

我有正常的txt文件中的表脚本也我有程序和功能的脚本。现在,我想从Java读取该文件,我想操作火灾DB上的字符串(脚本)..是有可能的.. 我已经写了所有的DML查询语句,但在这里我想使用来自Java的DDL查询..任何一个可以帮助我..从java文件创建程序/表

回答

0

用BufferedReader读取脚本(请参阅some examples)将每行添加到StringBuilder。然后使用JDBC来创建Statement并调用它的执行,并将您的stringbuilder对象作为字符串参数。

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

查看J ava Tutorial lesson on SQL Statements for Creating a Stored Procedure

如果您的文件包含多个脚本,则需要处理分隔符并用此方法遍历脚本。