public class ReadExcel {
public static void readExcel(File os) throws Exception {
BookForm bookForm=null;
Workbook wb = Workbook.getWorkbook(os);
Sheet s = wb.getSheet("Sheet1");
int i=1;
Cell c2=null,c3=null,c4=null,c5=null,c6=null;
String sql="";
while(i<5){
ConnDB conn=new ConnDB();
bookForm=new BookForm();
c2=s.getCell(2,i);
bookForm.setSpeciality(c2.getContents());
c3=s.getCell(5,i);
bookForm.setBookID(c3.getContents());
c4=s.getCell(6,i);
bookForm.setCreatetime(c4.getContents());
c5=s.getCell(7,i);
bookForm.setChecktime(c5.getContents());
c6=s.getCell(8,i);
bookForm.setQueryID(c6.getContents());
sql="Insert into tb_bookinfo(speciality,bookID,createtime,checktime,queryID) values('"+bookForm.getSpeciality()+"','"+bookForm.getBookID()+"','"+bookForm.getCreatetime()+"','"+bookForm.getChecktime()+"','"+bookForm.getQueryID()+"')";
conn.executeUpdate(sql);
i++;
System.out.println(bookForm.getSpeciality());
conn.close();
}
}
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
File f = new File("c:\\book.xls");
readExcel(f);
}}为什么,我只得到一个记录呢??
public static void readExcel(File os) throws Exception {
BookForm bookForm=null;
Workbook wb = Workbook.getWorkbook(os);
Sheet s = wb.getSheet("Sheet1");
int i=1;
Cell c2=null,c3=null,c4=null,c5=null,c6=null;
String sql="";
while(i<5){
ConnDB conn=new ConnDB();
bookForm=new BookForm();
c2=s.getCell(2,i);
bookForm.setSpeciality(c2.getContents());
c3=s.getCell(5,i);
bookForm.setBookID(c3.getContents());
c4=s.getCell(6,i);
bookForm.setCreatetime(c4.getContents());
c5=s.getCell(7,i);
bookForm.setChecktime(c5.getContents());
c6=s.getCell(8,i);
bookForm.setQueryID(c6.getContents());
sql="Insert into tb_bookinfo(speciality,bookID,createtime,checktime,queryID) values('"+bookForm.getSpeciality()+"','"+bookForm.getBookID()+"','"+bookForm.getCreatetime()+"','"+bookForm.getChecktime()+"','"+bookForm.getQueryID()+"')";
conn.executeUpdate(sql);
i++;
System.out.println(bookForm.getSpeciality());
conn.close();
}
}
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
File f = new File("c:\\book.xls");
readExcel(f);
}}为什么,我只得到一个记录呢??
代码注释
xls文件描述
打印结果
这个也放进去,