package com.cn.gao;
import java.util.List;
public class FromExcelToDb {
public static void main(String[] args) {
//å¾å°è¡¨æ ¼ä¸ææçæ°æ®
List<Stu> listExcel=StuService.getAllByExcel("d://book.xls");
/*//å¾å°æ°æ®åºè¡¨ä¸ææçæ°æ®
List<Stu> listDb=StuService.getAllByDb();*/
DBhelper db=new DBhelper();
for (Stu stuEntity : listExcel) {
int id=stuEntity.getId();
if (!StuService.isExist(id)) {
//ä¸åå¨å°±æ·»å
String sql="insert into student (name,sex,num) values(?,?,?)";
String[] str=new String[]{stuEntity.getName(),stuEntity.getSex(),stuEntity.getNum()+""};
db.AddU(sql, str);
}else {
//åå¨å°±æ´æ°
String sql="update student set name=?,sex=?,num=? where id=?";
String[] str=new String[]{stuEntity.getName(),stuEntity.getSex(),stuEntity.getNum()+"",id+""};
db.AddU(sql, str);
}
}
System.out.println("æ°æ®æ´æ°æåï¼");
}
}
温馨提示:答案为网友推荐,仅供参考