gpt4 book ai didi

mysql - 如何忽略重复键并继续在 mysql 中插入?

转载 作者:行者123 更新时间:2023-11-29 05:26:16 25 4
gpt4 key购买 nike

我正在读取 .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)

关于mysql - 如何忽略重复键并继续在 mysql 中插入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19910427/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com