我有一个数据库,我需要在那里插入一个新记录。我尝试使用PreparedStatement。
//Executing the INSERT query
String addSql = "INSERT INTO savedforms (Patientfnr, Patientname) VALUES (?, ?)";
//PreparedStatement for INSERT sql
java.sql.PreparedStatement stmt1 = connection.prepareStatement(addSql);
stmt1.setString(1, patientnumber);
stmt1.setString(2, patientname);
//Execute query
stmt1.executeUpdate(addSql);
并收到以下错误:
com.mysql.jdbc.exceptions.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
如何解决?
答案 0 :(得分:2)
答案 1 :(得分:0)
请注意,因为该方法声明不应在PreparedStatement或CallableStatement上调用它。
检查javadoc是否有这种方法