I am trying to delete a record from a database using the following code in Java
try {
Statement st = db.con.createStatement();
con.stmt = st.executeUpdate("DELETE FROM item, WHERE Name=" + textField_name.getText());
however “stmt”, (which is my PreparedStatement initialized in my connection class), is underlined and the code doesn’t compile.
That’s because
executeUpdatereturns anint, and presumablycon.stmtisn’t anintvariable.You shouldn’t write your SQL that way in the first place though (it’s invalid anyway due to the comma after
item) – you should use a prepared statement:That way you don’t open yourself up to SQL injection attacks.