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
  • 123,187
  • 45
  • 217
  • 223
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
  • 7,192
  • 8
  • 42
  • 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,296
  • 1
  • 20
  • 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,249
  • 5
  • 25
  • 36