ユーザが削除フィールドに間違ったIDを入力したときに、ポップアップする際にエラーが発生したかった。しかし、間違ったIDが入力されたとしても、依然として照会は続行されますが、データは削除されません。ここに私のコードです:データベースで削除が成功したかどうかを確認するには?
String value = jTextField19.getText();
if (value == null || "".equals(value)) {
JOptionPane.showMessageDialog(null, "The field is blank!");
} else {
theQuery("DELETE FROM inventorydb WHERE item_id=('"+jTextField19.getText()+"') AND item_id IS NOT NULL");
}
theQuery
方法:すべての
private void theQuery(String query) {
Connection con = null;
Statement st = null;
try {
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/inventory", "root", "");
st = con.createStatement();
st.executeUpdate(query);
JOptionPane.showMessageDialog(null, "Done!");
} catch (Exception ex) {
JOptionPane.showMessageDialog(null,"Error!");
}
}
[値]の実行時の値とは何ですか? – David