Android Sqlite Database Table Not Being Created
I'm following along in an Android for beginner's book and am trying to make a mini app to learn about using SQLite databases. I've built a DataManager class which creates a databas
Solution 1:
Use proper spacing before "text" like follows :
StringnewTableQueryString="create table "
+ TABLE_N_AND_A + " ("
+ TABLE_ROW_ID
+ " integer primary key autoincrement not null,"
+ TABLE_ROW_NAME
+ " text not null,"
+ TABLE_ROW_AGE
+ " text not null);";
Solution 2:
privatestaticfinalStringCREATE_DATABASE="create table " + DB_TABLE + " ("+ COLORNAME + " text not null);";
private SQLiteHelper sqLiteHelper;
private SQLiteDatabase sqLiteDatabase;
private Context context;
publicSQLiteAdapter(Context c){
context = c;
}
public SQLiteAdapter openToRead()throws android.database.SQLException {
sqLiteHelper = newSQLiteHelper(context, DB_NAME, null, VERSION);
sqLiteDatabase = sqLiteHelper.getReadableDatabase();
returnthis;
}
public SQLiteAdapter openToWrite()throws android.database.SQLException {
sqLiteHelper = newSQLiteHelper(context, DB_NAME, null, VERSION);
sqLiteDatabase = sqLiteHelper.getWritableDatabase();
returnthis;
}
publicvoidclose(){
sqLiteHelper.close();
}
publiclonginsert(String content){
ContentValuescontentValues=newContentValues();
contentValues.put(COLORNAME, content);
return sqLiteDatabase.insert(DB_TABLE, null, contentValues);
}
publicintdeleteAll(){
return sqLiteDatabase.delete(DB_TABLE, null, null);
}
public String queueAll(){
String[] colors = newString[]{COLORNAME};
Cursorcursor= sqLiteDatabase.query(DB_TABLE, colors,
null, null, null, null, null);
Stringresult="";
intindex_CONTENT= cursor.getColumnIndex(COLORNAME);
for(cursor.moveToFirst(); !(cursor.isAfterLast()); cursor.moveToNext()){
result = result + cursor.getString(index_CONTENT) + "\n";
}
return result;
}
Check this Article
Click here!
Post a Comment for "Android Sqlite Database Table Not Being Created"