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

文本格式:"POLONIUS,lordchamberlain."PERSONA,7,13,11,"HORATIO,friendtoHamlet."PERSONA,7,14... 文本格式:"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."
展开
 我来答
jsf126
2006-05-28 · 超过25用户采纳过TA的回答
知道答主
回答量:100
采纳率:0%
帮助的人:0
展开全部
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()这个函数你自己根据所要连的数据库改一下吧
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式