2017  Kodetalk | Feedback | Privacy Policy | Terms | About

Issue with question mark in jdbc PreparedStatement


I am trying to use parameter binding with jdbc for querying a mysql table, but it is showing syntax error for the question mark in my statement.


Here is a quick example, to give you a sense of how it looks in code:

String sql = "update SalesPerson set firstname=? , lastname=? where id=?";
PreparedStatement preparedStatement =        connection.prepareStatement(sql);
preparedStatement.setString(1, "Gary");

preparedStatement.setString(2, "Larson");

preparedStatement.setLong  (3, 123);

int rowsAffected = preparedStatement.executeUpdate();

Answer is