我正在读取.xls文件(excel)并将其插入到我的数据库中。我使用jsp来执行此操作,如果没有重复的密钥,则可以正常工作。
patientId = list1.get(i).toString();
patientFname = list2.get(i).toString();
patientLname = list3.get(i).toString();
patientMname = list4.get(i).toString();
patientGender = list5.get(i).toString();
patientBirthday = list6.get(i).toString();
patientAge = list7.get(i).toString();
patientAddress = list8.get(i).toString();
patientCompany = list9.get(i).toString();
ResultSet rs=st.executeQuery("SELECT idpatients FROM patients");
if (rs.first()) {
}
st.executeUpdate("insert into patients(idpatients,pfirstname,plastname,pmiddlename,gender,birthdate,age,address,company) values('"+patientId+"','"+patientFname+"','"+patientLname+"','"+patientMname+"','"+patientGender+"','"+patientBirthday+"','"+patientAge+"','"+patientAddress+"','"+patientCompany+"')");
如果存在重复的主键,它将无法正常工作,我想忽略它并继续下一个数据。
如果您只想忽略主键冲突,则可以使用
INSERT IGNORE INTO patients (columns here) VALUES (values here)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句