我一直在尝试创建一个SQLite数据库。但是只添加了一行。 (cursor.getCount()给出1)。任何人都可以告诉我我的代码有什么问题。
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);
}}
正在访问此信息的代码:
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();