由access导出txt的数据文件,怎么用程序识别文件,并把txt里面的字段识别出来呢!(txt里面有格式) 由access导出txt的数据文件,怎么用程序识别文件,并把txt里面的字段识别出来呢!(txt里面有格式). aaa bbb ccc ddd 1 a b c 2 aa bb cc我想把数据识别出来,再插入到orcale数据库里面!怎么实现呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 使用readLine()的方法,每次读取一行,然后再处理这个字符串。BufferedReader br = new BufferedReader(new FileReader(new File("文件地址"))); readLine()得到的是 String 然后用String []row=str.split("[\\t]");就把那些保存在一个树组里面了 Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); String url="jdbc:oracle:thin:@localhost:1521:orcl"; // orcl为你的oracle数据库的SID String user="scott"; String password="tiger"; java.sql.Connection conn= java.sql.DriverManager.getConnection(url,user,password); PreparedStatement ps = null; BufferedReader in=new BufferedReader(new FileReader("c:\\cc.txt")); String s=""; int i = 0; String sql = ""; while ( (s=in.readLine()) != null){ s = s.trim(); s = s.replaceAll("[ ]+",","); String[] strItem = s.split(" "); if (0 == i){//字段名 sql = "insert into yourtable("+s+")values("; for(int j=0 ; j<strItem.length; ++j){ sql = sql+"?,"; } if (sql.endsWith(",")) sql = sql.substring(0,sql.length()-1); } else {//字段值 //将数组strItem插入Oracle数据库 //得到数据库连接 java.sql.ResultSet rs = null; try { ps = conn.prepareStatement(sql); for(int j=0;j<strItem.length;++j){ ps.setString(j, strItem[j]); } ps.addBatch(); } catch (java.sql.SQLException e) { } finally { ps.close(); } //end 插入 } ++i; } ps.executeBatch(); conn.close(); conn = null; for(int j=0;j<strItem.length;++j){ ps.setString(j, strItem[j]);}改为for(int j=0;j<strItem.length;++j){ ps.setString(j+1, strItem[j]);} 请问,如何查看Java1.7中的类图,所有的,谢谢 关于单态的一点疑惑 請問如何把製作好的套件結合新的.java檔 j2SE中有什么值得去深究!!!谢谢大家给点看法! 怎么设置开机运行一软件 在写一个applet时候出现的问题,希望高手指点。 往Vector里放对象,放得郁闷之极,到底是程序代码问题还是JDK问题了? application中的按钮怎么才能在点击时发出声音?------能者相助 jbuilder8编辑代码时,光标位置经常显示不正常,如何改正? 一个很困扰我的问题-中奖 谁有JTGO的入门教程? 简单问个socket的问题
BufferedReader br = new BufferedReader(new FileReader(new File("文件地址")));
然后用String []row=str.split("[\\t]");就把那些保存在一个树组里面了
String url="jdbc:oracle:thin:@localhost:1521:orcl";
// orcl为你的oracle数据库的SID
String user="scott";
String password="tiger";
java.sql.Connection conn= java.sql.DriverManager.getConnection(url,user,password); PreparedStatement ps = null;
BufferedReader in=new BufferedReader(new FileReader("c:\\cc.txt"));
String s="";
int i = 0;
String sql = "";
while ( (s=in.readLine()) != null){
s = s.trim();
s = s.replaceAll("[ ]+",",");
String[] strItem = s.split(" ");
if (0 == i){//字段名
sql = "insert into yourtable("+s+")values(";
for(int j=0 ; j<strItem.length; ++j){
sql = sql+"?,";
}
if (sql.endsWith(","))
sql = sql.substring(0,sql.length()-1);
} else {//字段值
//将数组strItem插入Oracle数据库
//得到数据库连接
java.sql.ResultSet rs = null;
try {
ps = conn.prepareStatement(sql);
for(int j=0;j<strItem.length;++j){
ps.setString(j, strItem[j]);
}
ps.addBatch();
} catch (java.sql.SQLException e) {
} finally {
ps.close();
}
//end 插入
}
++i;
}
ps.executeBatch();
conn.close();
conn = null;
ps.setString(j, strItem[j]);
}
改为
for(int j=0;j<strItem.length;++j){
ps.setString(j+1, strItem[j]);
}