急求java源码 读取.txt文本生成sql server数据库文件

来源:百度知道 编辑:UC知道 时间:2024/06/06 09:51:29
文本格式:"POLONIUS, lord chamberlain. "
PERSONA,7,13,11,"HORATIO, friend to Hamlet."
PERSONA,7,14,12,"LAERTES, son to Polonius."
PERSONA,7,15,13,"LUCIANUS, nephew to the king."
PGROUP,8,16,20,"null"
PERSONA,9,17,14,"VOLTIMAND"
PERSONA,9,18,15,"CORNELIUS"
PERSONA,9,19,16,"ROSENCRANTZ"
PERSONA,9,20,17,"GUILDENSTERN"
PERSONA,9,21,18,"OSRIC"
GRPDESCR,10,22,19,"courtiers."
PERSONA,7,23,21,"A Gentleman"
PERSONA,7,24,22,"A Priest. "
PGROUP,8,25,26,"null"
PERSONA,9,26,23,"MARCELLUS"
PERSONA,9,27,24,"BERNARDO"
GRPDESCR,10,28,25,"officers."
PERSONA,7,29,27,"FRANCISCO, a soldier."

import java.sql.*;
import java.util.*;
import java.io.*;

public class DBImport
{
public static void main(String [] args)
{
try
{
execute(new File(args[0] + ".sql"));
}
catch(SQLException e)
{
while(e != null)
{
e.printStackTrace();
e.getNextException();
}
}
catch(IOException e)
{
e.printStackTrace();
}
}

private static void execute(File file)
throws IOException, SQLException
{
BufferedReader in = new BufferedReader(new FileReader(file));
String sql;
Connection conn = getConnection();
Statement stat = conn.createStatement();
while((sql = in.readLine()) != null)
{
stat.execute(sql);
}
in.close