java向mysql写入数据
private static void folderinput(String emlFile)throws Exception {
File file = new File(emlFile);
File[] tempListFiles = file.listFiles();
mysqlConnection.createTable();//创建maillist表格;
for (int i = 0; i< tempListFiles.length; i++) {
strings1=singleEmailAnalysis(tempListFiles[i]);//调用邮件解析函数,返回值为邮件相关域的string[]值;
mysqlConnection.writeTodb(strings1);//调用写数据库的操作函数
System.out.println(i);
}
}
int count = 0;//count用于统计显示解析邮件的序列号
public void writeTodb(String[] str) throws Exception {
try {
Statement s=returnStatement();
//建邮件列表
MysqlConnection mysqlConnection=new MysqlConnection();
mysqlConnection.createTable();
//插入数据
count++;
String sql1="insert into maillist values("+count+",'"+str[0]+"','"+str[1]+"','"+str[2]+"','"+str[3]+"','"+str[4]+"','"+str[5]+"','"+str[6]+"','"+str[7]+"')";
s.execute(sql1);
}catch (SQLException e) {
System.out.println("SQLException:"+e.getMessage());
}
}
这是写数据库的函数
问题::写入数据库的后一条记录覆盖了前一条记录,所以查询数据库显示的是最后一条记录,麻烦大神帮推敲以下是代码哪出问题?