【发布时间】:2026-01-25 09:50:02
【问题描述】:
String sql = " INSERT INTO `tblservice` (`ServiceID`,`accountID`, `Kind`, `Description`, `Price`, "
+ "`Quantity`, `Total`, `DateAndTime`) VALUES (NULL, ?, ?, ?, ?, ?, ?, ?)";
PreparedStatement pstm = conn.prepareStatement(sql);
pstm.setInt(1, this.accountID);
pstm.setString(2, "" + SelectionBox.getSelectedItem());
pstm.setString(3, desc);
pstm.setFloat(4, Float.parseFloat(PriceTF.getText()));
pstm.setFloat(5, Float.parseFloat(QuantityTF.getText()));
pstm.setFloat(6, this.getTotal());
pstm.setDate(7, dateAdded);
pstm.executeUpdate();
错误
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '?, ?, ?, ?, ?, ?, ?)' at line 1
【问题讨论】:
-
问题在哪里?上下文在哪里?我们需要更多信息,以便我们可以尽力帮助您...
-
错误信息告诉你该怎么做。你有什么问题?
-
我目前正在使用一个按钮来触发该代码,并且每次我按下该按钮时,它都会一直显示该错误并且没有任何操作触发我的意思是没有插入数据。那不应该是它应该在表中添加新数据,但它不起作用。