The best and recommended approach using SQLite is that you declare all table and column names static , final and class level .. for example:
// write table name public static final String TABLE_MESSAGE = "messages"; // and column name accordingly public static final String COLUMN_ID = "_id"; public static final String COLUMN_MESSAGE = "message";
therefore, the advantage of this approach is that you do not need to memorize spelling and case, etc. table and column names.
when you access any table or column, you simply use these static variables, for example:
// TABLE creation sql statement private static final String TABLE_CREATE = "create table " + TABLE_MESSAGE + "( " + COLUMN_ID + " integer primary key autoincrement, " + COLUMN_MESSAGE + " text not null);";
upon request:
database.query(TABLE_MESSAGE, new String[]{COLUMN_ID,COLUMN_MESSAGE}, null, null, null, null, null);
or it can be used in the cursor
int index = cursor.getColumnIndex(COLUMN_MESSAGE);
this will help you avoid such case sensitivity conflicts and spelling errors. :)
source share