SQL 1064 Syntax Error using a JDBC prepared statement

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

I have:

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


PreparedStateme         


        
3条回答
  •  南方客
    南方客 (楼主)
    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.

提交回复
热议问题