public void deleteBook(int temp) { try { query = "DELETE FROM ccItems WHERE ISBN = '"+temp+"'"; stmt.executeUpdate(query); JOptionPane.showMessageDialog(null, "Item Deleted !"); } catch(Exception e) { JOptionPane.showMessageDialog(null, "Error: Could not find ISBN or Already deleted."); } }
I have a deleteBook() method where it would delete items in my database. It works properly meaning deleting the specified item with the corresponding ISBN entered. Problem is, if the user inputs an ISBN which IS NOT IN MY DATABASE the try statement still executes. I think the catch statement must execute because the entered ISBN is not found in database.