香港进出口贸易骗局:急求java源码 读取.txt文本生成sql server数据库文件

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/05 11:34:25
文本格式:"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();
stat.close();
conn.close();
}

public static Connection getConnection()
throws IOException, SQLException
{
Properties props = new Properties();
FileInputStream in = new FileInputStream("mysql.dat");
props.load(in);
in.close();
String drivers = props.getProperty("jdbc.drivers");
if (drivers != null)
System.setProperty("jdbc.drivers", drivers);
return
DriverManager.getConnection(props.getProperty("url"), props);
}
}
最后一块,就是getConnection()这个函数你自己根据所要连的数据库改一下吧