public final class AccessTextFile { /**
* 1. 将流中的文本读入一个 StringBuffer 中
* @throws IOException
*/
public void readToBuffer(ArrayList list, InputStream is)
throws IOException {
String line; // 用来保存每行读取的内容
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
line = reader.readLine(); // 读取第一行
while (line != null) { // 如果 line 为空说明读完了
list.add(line); // 将读到的内容添加到 buffer 中
// buffer.add("\n"); // 添加换行符
line = reader.readLine(); // 读取下一行
}
}
public static void main(String[] args) throws IOException, SQLException {
Connection conn=null;
String sSQL=null;
Statement stmt=null;
DBConnectionManager connMgr=null;
AccessTextFile test = new AccessTextFile();
InputStream is = new FileInputStream("E:\\test.txt");
//StringBuffer buffer = new StringBuffer();
ArrayList list = new ArrayList();
test.readToBuffer(list, is);
System.out.println(list.get(0)); // 将读到 buffer 中的内容写出来
is.close();
// String sSQL= "insert into sm_send_msg([dest_num],[content],[req_date],[send_date])";
// sSQL=sSQL+"values(" + list.get(0)+")";
sSQL=new StringBuffer().append("Insert into sm_send_msg(")
.append("[dest_num],[content],[req_date],[send_date],[note],[result],[udp_seq],[send_times]")
.append(") values('")
.append(list.get(0))
.append("','")
.append(list.get(1))
.append("',now(),now(),1,1,0,0)")
.toString();
connMgr = DBConnectionManager.getInstance();
conn = connMgr.getConnection("acc");
stmt=conn.createStatement();
stmt.execute(sSQL);
}
}该功能是想实现从文本文件中读出数据难后存入ACCESS中,程序编译时没出现错误,可就是不知道为什么插入数据没成功。。高手们帮帮忙!!
* 1. 将流中的文本读入一个 StringBuffer 中
* @throws IOException
*/
public void readToBuffer(ArrayList list, InputStream is)
throws IOException {
String line; // 用来保存每行读取的内容
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
line = reader.readLine(); // 读取第一行
while (line != null) { // 如果 line 为空说明读完了
list.add(line); // 将读到的内容添加到 buffer 中
// buffer.add("\n"); // 添加换行符
line = reader.readLine(); // 读取下一行
}
}
public static void main(String[] args) throws IOException, SQLException {
Connection conn=null;
String sSQL=null;
Statement stmt=null;
DBConnectionManager connMgr=null;
AccessTextFile test = new AccessTextFile();
InputStream is = new FileInputStream("E:\\test.txt");
//StringBuffer buffer = new StringBuffer();
ArrayList list = new ArrayList();
test.readToBuffer(list, is);
System.out.println(list.get(0)); // 将读到 buffer 中的内容写出来
is.close();
// String sSQL= "insert into sm_send_msg([dest_num],[content],[req_date],[send_date])";
// sSQL=sSQL+"values(" + list.get(0)+")";
sSQL=new StringBuffer().append("Insert into sm_send_msg(")
.append("[dest_num],[content],[req_date],[send_date],[note],[result],[udp_seq],[send_times]")
.append(") values('")
.append(list.get(0))
.append("','")
.append(list.get(1))
.append("',now(),now(),1,1,0,0)")
.toString();
connMgr = DBConnectionManager.getInstance();
conn = connMgr.getConnection("acc");
stmt=conn.createStatement();
stmt.execute(sSQL);
}
}该功能是想实现从文本文件中读出数据难后存入ACCESS中,程序编译时没出现错误,可就是不知道为什么插入数据没成功。。高手们帮帮忙!!
System.out.println(list.get(0)); // 将读到 buffer 中的内容写出来
这句话是否正确的输出?如果正确的输出,那么问题可能出现在你下面的 DBConnectionManager 里面。connMgr = DBConnectionManager.getInstance();
conn = connMgr.getConnection("acc");
stmt=conn.createStatement();
stmt.execute(sSQL);// 可以尝试在这里 加一个 查询的 SQL 语句,看看能否检索到数据
// 如果能检索到,但是程序结束后,你在Access里面却看不到。
// 那么你在这个位置加一句 conn.commit(); 之类的语句。