我正在尝试更新 JAVA 代码上数据库的值,但是当我尝试这样做时,它告诉我“主键的重复条目(nameOfSomething)”;即使 PK 不存在,也会给我这个错误,我不知道为什么。欢迎所有帮助;如果需要更多代码,我很乐意添加它。提前致谢。
/**
SO THE NEW ERROR WOULD BE ON THE IF/ELSE STATEMENT, WHICH IS TRHOWING THE ELSE, THAT SAYS "DATA WAS NOT UPDATED".
*/
JButton btnUpdate = new JButton("Update");
btnUpdate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String petname = txtName.getText();
String petphoto = txtPhoto.getText();
String pettype = txtType.getText();
String color = txtColor.getText();
int gender = Integer.parseInt(txtGender.getText());
int isSterilized = Integer.parseInt(txtSterilized.getText());
//DATE
String pedigree = txtPedigree.getText();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String date_entry = df.format(datePicker.getDate());
//END
String vaccine1 = txtVaccine1.getText();
String vaccine2 = txtVaccine2.getText();
String vaccine3 = txtVaccine3.getText();
Connection conn = null;
PreparedStatement pstmt = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/refugio","root","2797");
pstmt = conn.prepareStatement("UPDATE PETS SET PETPHOTO=?, PETTYPE=?, COLOR=?,GENDER=?,ISSTERILIZED=?,PEDIGREE=?,DATE_ENTRY=?,"
+ "VACCINE1=?,VACCINE2=?,VACCINE3=? WHERE PETNAME=?"); //NEW CHANGE HERE
}
}
});
慕尼黑8549860
白板的微信
相关分类