㈠ 濡备綍鐢↗ava瀹炵幇鎶奺xcel琛ㄤ腑镄勬暟鎹瀵煎叆鍒癿ysql鏁版嵁搴揿凡链夌殑琛ㄤ腑
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("鏁版嵁镟存柊鎴愬姛锛");
}
}