Praveenkumar Beedanal
Praveenkumar Beedanal

Reputation: 834

Syntax error in delete statement

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);

Upvotes: 0

Views: 409

Answers (1)

BackSlash
BackSlash

Reputation: 22233

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();

Upvotes: 3

Related Questions