嗨,我正在尝试使用预准备语句将数据插入数据库,但我得到语法错误,请你帮忙
public boolean SignUp(String last_name, String first_name,String email, String password,String confirm_password,String phone){
Connect connect = new Connect();
Connection conn = connect.Connection();
java.sql.PreparedStatement preparedStatement = null;
//NULL is the column for auto increment
String insertQuery = "INSERT INTO users VALUES (NULL, ?, ?, ?, ?, ?, ?)";
preparedStatement = conn.prepareStatement(insertQuery);
preparedStatement.setString(1, last_name);
preparedStatement.setString(2, first_name);
preparedStatement.setString(3, email);
preparedStatement.setString(4, password);
preparedStatement.setString(5, confirm_password);
preparedStatement.setString(6, phone);
int rs = preparedStatement.executeUpdate(insertQuery);
conn.close();
Run Code Online (Sandbox Code Playgroud)
}
这是错误消息
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
Run Code Online (Sandbox Code Playgroud)
小智 5
我找到了答案:)
使用preparedStatement.execute()而不是executeUpdate(sql).您已经设置了sql和params - executeUpdate(sql)中的新设置会覆盖绑定.
| 归档时间: |
|
| 查看次数: |
2300 次 |
| 最近记录: |