public void refleshListView() {dba = new Db(MainActivity.this);SQLiteDatabase dbaRead = dba.getReadableDatabase();Cursor c = dbaRead.query("user2", null, null, null, null, null, null);mA = new SimpleCursorAdapter(MainActivity.this, R.layout.user_info, c,new String[]{"_id"}, new int[]{R.id._id});lieBiao.setAdapter(mA);}public void onClick(View view) {refleshListView();String shuru = textSR.getText().toString();String neirong = "你输入的内容是:" + shuru;Toast.makeText(MainActivity.this, neirong, Toast.LENGTH_LONG).show();dba = new Db(MainActivity.this);SQLiteDatabase dbaWrite = dba.getWritableDatabase();ContentValues cv = new ContentValues();cv.put("_id", shuru);dbaWrite.insert("user2", null, cv);}public void onCreate(SQLiteDatabase db) {db.execSQL("CREATE TABLE user2(_id INT DEFAULT 0)");db.execSQL("CREATE TABLE user3(_id INT DEFAULT 0)");}写入和读取都只能使用user2,如果使用user3就会报错,说不存在table:user3报错内容如下:PID: 7829android.database.sqlite.SQLiteException: no such table: user3 (code 1): , while compiling: SELECT * FROM user3
1 回答
慕标琳琳
TA贡献1830条经验 获得超9个赞
用如下语法:
alter table table_name rename table_new_name;
其中,table_name是旧表名,table_new_name是新表名。
添加回答
举报
0/150
提交
取消