0

I am trying to delete the record from my "student" table, the table has two column rollno and student name.

I am using a PreparedStatement but I am getting some error. I could not understand the error. The error is:

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 '?' at line 1

here is my code

    String query = "delete from student where rollno = ?";

    PreparedStatement pst = con.prepareStatement(query);

      pst.setInt(1, 7);
     pst.executeUpdate(query);
1
  • 2
    You forgot to share the most important part: How do you execute the query? Commented May 28, 2017 at 15:21

1 Answer 1

3

Likely you are calling the execute like this:

pst.executeUpdate(query);

This will execute the raw query, without the parameter you set before.

You want to execute the prepared query instead, so just use:

pst.executeUpdate();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.