shaam shaam - 9 months ago 33
Java Question

the right syntax to use near '? WHERE Reg = ?'

public static void updateData(Connection con, String make, String reg) {
String selectString = "UPDATE Cars SET Make = ? WHERE Reg = ?";
PreparedStatement pStmt = con.prepareStatement(selectString);
pStmt.setString(1, make);
pStmt.setString(2, reg);


I am getting the following error for this piece of code:

SQL Exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '? WHERE Reg = ?' at line 1

I'll appreciate if someone could help me out. I've searched around but my problem is quite different to solutions i've found.

Answer Source

Use the overloaded executeUpdate meant for PreparedStatements