我统一10条插入一次,可是最后数据库只有第十条数据,前九条都没有,插入几次都是,怎么办
List backList = new ArrayList();
Connection con = getConnection();
PreparedStatement stat = null;
String str= null;
int j = 0;
for(int i=0;i<list.size();i++){
str = list.get(i);
String[] arr = str.split(",");
j++;
if(arr.length ==10){
try {
String name = arr[0];
String pinyin = arr[1];
String age = arr[2];
String sex = arr[3];
String phone = arr[4];
String mobilephone = arr[5];
String address = arr[6];
String birthday = arr[7];
String birthPlace = arr[8];
String company = arr[9];
//根据参数动态拼一个insert语句("+deptno+",'"+dname+"','"+loc+"')"
String sql = "insert into user_info "+"values ('"+name+"','"+pinyin+"','"+age+"','"+
sex+"','"+phone+"','"+mobilephone+"','"+address+"','"+birthday+"','"+birthPlace+"','"+company+"')";
stat = con.prepareStatement(sql);
System.out.println(sql);
stat.addBatch();
System.out.println("sql语句加入批处理中");
} catch (SQLException e2) {
// TODO Auto-generated catch block
}
}
if(j == list.size()){
int s [] = stat.executeBatch();
for(int a:s){
System.out.println(a);
}
}
}
try {
stat.close();
con.close();
} catch (SQLException e1) {
e1.printStackTrace();
}