Can anybody point what is wrong with my code? I have 2 tables and I am trying to delete a row from 2 tables. I was able to delete a row from 1 table but delete a row from 2 tables did not work. Here is my code:
String id = theId.getText();
String id2 = theId2.getText();
textArea.setText("");
try (Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/dealer", "root", "admin")) {
stmt = connection.prepareStatement("DELETE FROM person, cars WHERE driverID = ?, carID = ?");
if (stmt != null) {
stmt.setString(1, id);
stmt.setString(2, id2);
stmt.executeUpdate();
}
The error I got
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an
error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'WHERE driverID
= '1', carID = '1'' at line 1
Thank you so much!