我正在更新,删除和创建日历中的事件。我有很多方法。但是,如果我尝试运行其中任何一个,它会给我SQLITE BUSY错误。我在每种方法后都关闭了连接。那可能是什么问题呢?我知道我有太多关系,但我确实关闭了它们。
public static DatabaseConnection db = new DatabaseConnection();
public static ArrayList<EventModel> retrieveAllInfo() {
ArrayList<EventModel> listOfEvents = new ArrayList<EventModel>();
ResultSet rs = null;
String dbQuery;
db.getConnection();
dbQuery = "SELECT * FROM ToDoList";
rs = db.readRequest(dbQuery);
try {
while (rs.next()) {
EventModel model = new EventModel();
model.setId(rs.getInt("id"));
model.setEventName(rs.getString("eventName"));
model.setDate(rs.getString("day"));
model.setTime(rs.getString("time"));
listOfEvents.add(model);
}
} catch (Exception e) {
e.printStackTrace();
}
db.terminate();
return listOfEvents;
}
public static boolean updateEvent(EventModel eventmodel) {
//declare local variables
boolean success = false;
String dbQuery;
PreparedStatement pstmt;
db.getConnection();
dbQuery = "UPDATE ToDoList SET eventName = ?, time = ?, day = ? WHERE id = " + eventmodel.getId();
pstmt = db.getPreparedStatement(dbQuery);
try {
pstmt.setString(1, eventmodel.getEventName());
pstmt.setString(2, eventmodel.getTime());
pstmt.setString(3, eventmodel.getDate());
if (pstmt.executeUpdate() == 1)
success = true;
pstmt.close();
} catch (Exception e) {
e.printStackTrace();
}
db.terminate();
return success;
}