0
        String myquery="INSERT INTO likestatus values(?,?)";


        PreparedStatement st1=con.prepareStatement(myquery);
        st1.setString(1,Integer.toString(rid));
        st1.setString(2, id);
        st1.executeUpdate(myquery);

the error I am getting is

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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

Haim Evgi
  • 120,002
  • 45
  • 212
  • 219
coder
  • 19
  • 1
  • 10

3 Answers3

1

In your final line you have passed in the sql string again bypassing the prepared statement functionality. Just change the final line to this:

st1.executeUpdate();

PreparedStatement extends Statement so executeUpdate(String) is still available however you don't use it normally as the object knows has the sql, you use executeUpdate() instead.

3urdoch
  • 6,992
  • 8
  • 41
  • 58
-1

It seems that you need to specify the concrete column names you provide values for:

INSERT INTO likestatus (column1, column2) values (?, ?)
Flinsch
  • 4,223
  • 1
  • 19
  • 29
-1

In your code:

st1.setString(2, id);

type of id is string? you need to make sure you are using the corresponding setXXX method corresponds to the datatype.

James.Xu
  • 8,101
  • 5
  • 24
  • 36