SQL 1064 Syntax Error using a JDBC prepared statement

后端 未结 3 1036
暗喜
暗喜 2021-01-22 19:39

I have:

String query = \"INSERT INTO Basestations VALUES(?, ?, ?, ?, ?, ?, ?,\"
               + \"?, ?, ?, ?, ?, ?, ?, ?)\";                  


PreparedStateme         


        
相关标签:
3条回答
  • 2021-01-22 19:42

    You're passing an string representing an invalid SQL statement to the executeUpdate() method when you don't need to. Try just doing prep.executeUpdate();.

    0 讨论(0)
  • 2021-01-22 19:55

    In your last line you don't need pass the variable query.

    So change

     prep.executeUpdate(query);
    

    For:

     prep.executeUpdate();
    
    0 讨论(0)
  • 2021-01-22 20:06

    The main error is here:

     // incorrect
     prep.executeUpdate(query);
    
     // correct
     prep.executeUpdate();
    

    But please try to put your SQL in the following form:

    UPDATE table_name(field1, field2, field3) VALUES(?, ? ,?)
    

    This will prevent your code from breaking if there is an update to the table.

    0 讨论(0)
提交回复
热议问题