1

I am doing a update, delete and create of events in my Calendar. I have many methods. However, if i try to run any of them, it gives me SQLITE BUSY Error. I have closed the connection after every methods. So what could be the problem? I know I have too many connections, but i did close them.

    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;
 }
4

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.