我当前正在编写一个程序,可以在其中删除数据库中的某些条目。我可以做到,但是我想添加一个JOptionPane屏幕,以显示何时可以找到它(因此找不到名称时,不应该找到它,并显示一条消息,指出找不到它)。我尝试使用结果语句,但这似乎不起作用。如果有人知道该怎么做,请对此发表评论!
private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {
ArrayList<Cookbook > recipes = new ArrayList();
String name = txtName.getText();
try {
String url = "jdbc:derby://localhost:1527/Cookbook";
Connection conn = DriverManager.getConnection(url);
String query = "DELETE from RECIPES WHERE NAME = ?";
PreparedStatement pst = conn.prepareStatement(query);
pst.setString(1, name);
pst.executeUpdate();
JOptionPane.showMessageDialog(null, name + " was sucessfully deleted");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "was not found or could not be deleted");
}