I have been trying to create an SQLite database. But only one row is being added. (cursor.getCount() gives 1). Can anyone please tell me what is wrong with my code.
class Dbhelper extends SQLiteOpenHelper{
Dbhelper(Context context)
{
super(context,"database00",null,1);
}
@Override
public void onCreate(SQLiteDatabase db)
{
db.execSQL("CREATE TABLE TABLE00 (_id INTEGER PRIMARY KEY AUTOINCREMENT,"
+ "DISPLAY TEXT);");
insertD(db,"a");
insertD(db,"b");
insertD(db,"c");
}
@Override
public void onUpgrade(SQLiteDatabase db,int oldVersion,int newVersion) {}
private static void insertD(SQLiteDatabase db,String display)
{
ContentValues d=new ContentValues();
d.put("DISPLAY",display);
db.insert("TABLE00", null, d);
}}
Code that is accessing this info:
SQLiteOpenHelper Dbhelper = new Dbhelper(this);
SQLiteDatabase db = Dbhelper.getReadableDatabase();
Cursor cursor=db.rawQuery("select * from TABLE00",null);
cursor.moveToFirst();
int msg3 = cursor.getCount();
TextView textView = (TextView) findViewById(R.id.textView3); textView.setText("No of rows:"+msg3);
cursor.close();
db.close();