我正在编写一个练习程序,允许我编辑数据库。我有它以便加载并显示数据,并且有它可以添加条目。我现在在删除条目时遇到问题,代码在下面,当我运行它时,出现错误消息:org.sqlite.SQLiteException:[SQLITE_ERROR] SQL错误或数据库丢失(“(“附近:语法错误) ,我已经浏览了代码,没有看到任何错误。
@FXML
private void selectStudent(ActionEvent event) throws SQLException{
StudentData stud = studenttable.getSelectionModel().getSelectedItem();
String sqlRemove = "DELETE FROM Students(id, fname, lname, email, dob) VALUES (?, ?, ?, ?, ?)";
try {
if (stud != null) {
Connection conn = dbConnection.getConnection();
PreparedStatement st = conn.prepareStatement(sqlRemove);
st.setString(1, this.idcolumn.getText());
st.setString(2, this.fnamecolumn.getText());
st.setString(3, this.lnamecolumn.getText());
st.setString(4, this.emailcolumn.getText());
st.setString(5, this.dobcolumn.getText());
st.execute();
conn.close();
} else {
test.setText("Please select an Entry");
}
}catch (Exception ex){
ex.printStackTrace();
}
}
答案 0 :(得分:1)
DELETE FROM Students(id, fname, lname, email, dob) VALUES (?, ?, ?, ?, ?)
不是有效的Delete查询,请尝试在sqlLite中运行相同的消息。
应为DELETE FROM Students where (pass any of one condition which returns a row value) i.e. id=?