shaam shaam - 29 days ago 5
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 = ?";
try
{
PreparedStatement pStmt = con.prepareStatement(selectString);
pStmt.setString(1, make);
pStmt.setString(2, reg);
pStmt.executeUpdate(selectString);
pStmt.close();

}...


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

Use the overloaded executeUpdate meant for PreparedStatements

pStmt.executeUpdate();