Problem accessing SQL database without error

Asked

Viewed 30 times

1

I have a code that uses SQL , and in this database , I have a column of dates, then I have a code that what it does is return the maxID (number of Rows, ie number of dates) and I have another code that goes to this column and returns the date with the ID specified in the parameter. For this to "work " I have a method that what it does is to loop by the method that returns the date with the ID specified in the parameter , and then with that date uses a Caldroid method , setBackgroundDrawable.

Well the problem is that it is not working but also has no error.

Method code that returns the maxID and ID(x date):

      public int getLastId() {
    String query = "SELECT MAX(id) AS max_id FROM " + TABLE_NAME;
    Cursor cursor = database.rawQuery(query, null);
    int id = 0;
    if (cursor.moveToFirst())
    {
        do
        {
            id = cursor.getInt(0);
        } while(cursor.moveToNext());

    }
    cursor.close();
    return id;

}

public String getDates(int numero){
    String date = "";
    String last_query = "SELECT " + COL_4  + " FROM " + TABLE_NAME  + " WHERE " + COL_1 + " = '" + numero + "'";
    Cursor c = database.rawQuery(last_query, null);
    if (c != null && c.moveToFirst())
    {
        date = c.getString(c.getColumnIndex("DIA")); // Return Value
    }
    c.close();
    return date;
}

}

method that calls these two methods with a loop:

      public void addToCalendar(){

    myDB = CustomApplication.getDatabaseHelper();
    ColorDrawable blue = new ColorDrawable(Color.BLUE);
    for(int i=0;i == myDB.getLastId();i++){
        String dt = myDB.getDates(i);
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd-MM-yyyy");
        Date teste = null;
        try {
            teste = sdf.parse(dt);
            caldroidFragment.setBackgroundDrawableForDate(blue,teste);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
}
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.