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();
錯誤Java的SQL INSERT preparedstatment錯誤
在查詢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
在哪裏的問題?上下文在哪裏?我們需要更多的信息,所以我們可以嘗試幫助你... – leobelones
錯誤消息告訴你該怎麼做。你的問題是什麼? – betseyb
我目前正在使用一個按鈕來觸發該代碼,並且每次我按下按鈕時,它都會繼續顯示該錯誤,並且沒有任何操作觸發我的意思是沒有數據正在被插入。這不應該是它應該在表中添加新的數據,但它不起作用。 – meltits