高分求助java小程序
高分求高手尽快帮忙,尽快用java写一个从文本文档中提取信息放到E:\db.mdb的access数据库的程序不用界面只要dos下能运行就行文本的格式是517.[Gaebe...
高分求高手尽快帮忙,尽快用java写一个从文本文档中提取信息 放到E:\db.mdb 的access数据库的程序 不用界面 只要dos下能运行就行 文本的格式是
517. [Gaebel, Cathy] [ Victim Witness Services Worker ] [ATTORNEY GENERAL]
[PICTON SATELLITE, Picton] [613-962-3005] [ cathy.gaebel@ontario.ca]
518. [Gaedecke, Gabrielle] [ Health & Long-Term Care ] [COUNCILS AND COORDINATORS]
[ONTARIO GOVERNMENT LIBRARIES COUNCIL, Toronto] [416-235-5935] [ phl_torontolibrary@ontario.ca]
519. [Gaedecke, Gabrielle] [ Library Technician ] [HEALTH AND LONG-TERM CARE]
[LIBRARY, Etobicoke] [416-235-5935] [ PHL_Torontolibrary@ontario.ca]
520. [Gaeta, David] [ Administrative Clerk ] [CABINET OFFICE]
[CORRESPONDENCE SERVICES UNIT, Toronto] [416-325-3750] [ david.gaeta@ontario.ca]
数字不要 只要每个中括号中的字 分别放进一个字段中
在线等
谁能在5点前给我 再加100分 展开
517. [Gaebel, Cathy] [ Victim Witness Services Worker ] [ATTORNEY GENERAL]
[PICTON SATELLITE, Picton] [613-962-3005] [ cathy.gaebel@ontario.ca]
518. [Gaedecke, Gabrielle] [ Health & Long-Term Care ] [COUNCILS AND COORDINATORS]
[ONTARIO GOVERNMENT LIBRARIES COUNCIL, Toronto] [416-235-5935] [ phl_torontolibrary@ontario.ca]
519. [Gaedecke, Gabrielle] [ Library Technician ] [HEALTH AND LONG-TERM CARE]
[LIBRARY, Etobicoke] [416-235-5935] [ PHL_Torontolibrary@ontario.ca]
520. [Gaeta, David] [ Administrative Clerk ] [CABINET OFFICE]
[CORRESPONDENCE SERVICES UNIT, Toronto] [416-325-3750] [ david.gaeta@ontario.ca]
数字不要 只要每个中括号中的字 分别放进一个字段中
在线等
谁能在5点前给我 再加100分 展开
展开全部
我也是初学者(学习了半年),做出来了,累死。
代码如下:
import java.io.*;
import java.sql.*;
import java.util.StringTokenizer;
public class TestAcess {
public static void main(String[] args) {
TestAcess ta=new TestAcess();
ta.FillAccess("sun.jdbc.odbc.JdbcOdbcDriver","jdbc:odbc:cliff","Table1","c:\\data.txt");
}
public void FillAccess(String DriverName,String connString,String TableName,
String FileName){
Connection con;
Statement sql;
try{
Class.forName(DriverName);
}
catch(ClassNotFoundException e){
System.out.println(""+e);
}
try {
con=DriverManager.getConnection(connString,"","");
sql=con.createStatement();
BufferedReader in = new BufferedReader(new FileReader(FileName));
String Datain;String Temp;
String[] InputData=new String[6];
while((Datain=in.readLine())!=null){
Datain+=in.readLine();
StringTokenizer st=new StringTokenizer(Datain,"[$]");
String temp="";
int i=0;
while(st.hasMoreTokens()){
temp=st.nextToken().trim();
if(temp.length()>4){
InputData[i]=temp.replaceAll(","," ");i++;
}
}
String temp1="insert into " + TableName +"(Name,Duty,Dept,Addr,Tel,Email) Values(";
for(int ii=0;ii<InputData.length;ii++){
temp1 += "'" + InputData[ii] +"',";
}
temp1=temp1.substring(0,temp1.length()-1);
temp1+=")";
sql.executeUpdate(temp1);
}
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (SQLException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
代码如下:
import java.io.*;
import java.sql.*;
import java.util.StringTokenizer;
public class TestAcess {
public static void main(String[] args) {
TestAcess ta=new TestAcess();
ta.FillAccess("sun.jdbc.odbc.JdbcOdbcDriver","jdbc:odbc:cliff","Table1","c:\\data.txt");
}
public void FillAccess(String DriverName,String connString,String TableName,
String FileName){
Connection con;
Statement sql;
try{
Class.forName(DriverName);
}
catch(ClassNotFoundException e){
System.out.println(""+e);
}
try {
con=DriverManager.getConnection(connString,"","");
sql=con.createStatement();
BufferedReader in = new BufferedReader(new FileReader(FileName));
String Datain;String Temp;
String[] InputData=new String[6];
while((Datain=in.readLine())!=null){
Datain+=in.readLine();
StringTokenizer st=new StringTokenizer(Datain,"[$]");
String temp="";
int i=0;
while(st.hasMoreTokens()){
temp=st.nextToken().trim();
if(temp.length()>4){
InputData[i]=temp.replaceAll(","," ");i++;
}
}
String temp1="insert into " + TableName +"(Name,Duty,Dept,Addr,Tel,Email) Values(";
for(int ii=0;ii<InputData.length;ii++){
temp1 += "'" + InputData[ii] +"',";
}
temp1=temp1.substring(0,temp1.length()-1);
temp1+=")";
sql.executeUpdate(temp1);
}
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (SQLException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
展开全部
可惜我现在很忙,召唤COLOR4YOU
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
就把数据库连接起来.然后用 insert语句就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
没给数据库表结构,怎么给你写?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
先用File类读取文本文件,然后用流读取文件中的行,获得每行的字符串后,建议您在原文本文件中的][后加上,号,然后用split(",")分割字符串为数组,循环数组生成一个insert的SQL语句,然后用Connection执行SQL
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询