如何从Java中删除访问记录?我已经尝试了以下方法,但是似乎没有用。
public void Delete() throws SQLException {
st.executeUpdate("DELETE FROM [AssignmentDetails] WHERE ([Entry Date],[Project ID],[Employee],[Hours Worked],[Firm Deadline],[Description of Assignment],[Additional Details],[ID]) = ('" + AbstractVariables.getEntryDate() + "','" + AbstractVariables.getProjectID() + "','" + AbstractVariables.getEmployee() + "','" + AbstractVariables.getHoursWorked() + "','" + AbstractVariables.getFirmDeadline() + "','" + AbstractVariables.getDescription() + "','" + AbstractVariables.getAdditionalDetails() + "','"+AbstractVariables.getID() + "')");
}
最佳答案
try {
Connection con;
Statement stmt;
String url = "jdbc:odbc:GameData.mdb";
// DATABASE CONNECTION MAGIC :-)
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(url, "user", "password");
stmt = con.createStatement();
// DELETE SOME SOME STUDENT DATA (RARELY USED IN GOOD PRACTICE)
stmt.executeUpdate("delete from students where phone = '000-0000'");
// DATABASE CLOSE/CLEANUP
stmt.close();
con.close();
}
catch(Exception e) {
e.printStackTrace();
}