嗨,我試圖插入語句,但不斷收到以下錯誤:在INSERT語句太少參數
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 3.
這裏是我的代碼:
try {
Statement stmt = con.createStatement();
String mySqlStatement = "INSERT INTO EntrantDetails (ID, Name, Surname, Gender, DOB ChipNum) VALUES (" + details.getIDNum()+ "," + details.getName() + "," + details.getSurname() + "," + details.getGender() + "," + details.getDOB() + "," + details.getChipNum() + ")";
stmt.executeUpdate(mySqlStatement);
}
catch (Exception ex)
{
ex.printStackTrace();
}
推測details.getName()返回一個字符串?如果是這樣,它應該被'引用'(並逃脫) –
關閉主題,但開始使用'PreparedStatement'! – NINCOMPOOP
也是DOB ChipNum的一個字段,或者是在那裏缺少逗號。如果它是一個字段是這個正確的表示,或者應該有[]圍繞它? –