原代码如下for (int i = 1; i < sheet.getRows(); i++) {
Integer stuId = Integer.parseInt( sheet.getCell(0, i).getContents());
System.out.println("插入第一行");
String name = sheet.getCell(1, i).getContents();System.out.println("插入第2行");
String nation = sheet.getCell(2, i).getContents();System.out.println("插入第3行");
String sex = sheet.getCell(3, i).getContents();System.out.println("插入第4行");
String birth =sheet.getCell(4, i).getContents();System.out.println("插入第5行");
String address = sheet.getCell(5, i).getContents();System.out.println("插入第6行");
Integer phone = Integer.parseInt( sheet.getCell(6, i).getContents());System.out.println("插入第7行");
Integer identity = Integer.parseInt( sheet.getCell(7, i).getContents());System.out.println("插入第8行");
String pwd = sheet.getCell(8, i).getContents();
System.out.println("插入第9行");
Studentinfo studentinfo = new Studentinfo(stuId, name, nation, sex, birth, address, phone, identity,pwd);
System.out.println("新建学生信息");
System.out.println("准备导入:"+ i +studentinfo.toString());
//保存数据
ses.save(studentinfo);
//每100条数据,提交一次。
if(i%100==0){
tx.commit();
System.out.println("已经导入第"+i/100+"批数据:"+ i +studentinfo.toString());
}
有trycath
try {
//从指定文件,创建工作表
book=Workbook.getWorkbook(file);
//得到工作表
Sheet sheet = book.getSheet(0);
r=sheet.getRows()-1;
//遍历工作表,插入数据到数据库
for (int i = 1; i < sheet.getRows(); i++) {
Integer stuId = Integer.parseInt( sheet.getCell(0, i).getContents());
System.out.println("插入第一行");
String name = sheet.getCell(1, i).getContents();System.out.println("插入第2行");
String nation = sheet.getCell(2, i).getContents();System.out.println("插入第3行");
String sex = sheet.getCell(3, i).getContents();System.out.println("插入第4行");
String birth =sheet.getCell(4, i).getContents();System.out.println("插入第5行");
String address = sheet.getCell(5, i).getContents();System.out.println("插入第6行");
Integer phone = Integer.parseInt( sheet.getCell(6, i).getContents());System.out.println("插入第7行");
Integer identity = Integer.parseInt( sheet.getCell(7, i).getContents());System.out.println("插入第8行");
String pwd = sheet.getCell(8, i).getContents();
System.out.println("插入第9行");
Studentinfo studentinfo = new Studentinfo(stuId, name, nation, sex, birth, address, phone, identity,pwd);
System.out.println("新建学生信息");
System.out.println("准备导入:"+ i +studentinfo.toString());
//保存数据
ses.save(studentinfo);
//每100条数据,提交一次。
if(i%100==0){
tx.commit();
System.out.println("已经导入第"+i/100+"批数据:"+ i +studentinfo.toString());
}
}
//不满100条时,提交
tx.commit();
} catch (BiffException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}catch (Exception e) {
}
return r;