2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

Issue with question mark in jdbc PreparedStatement

Hi,

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.

userimage

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