Android SQLite 相关

我想创建2个表这样对吗?

public class MyDatabaseHelper extends SQLiteOpenHelper {

private String CREATE_TABLE_USER = "create table USER(" + "username text,"
    + "usermima text," + ")";

private String CREATE_TABLE_STU = "create table STU(" + "id text,"
    + "name text," + "num text," + ")";

public MyDatabaseHelper(Context context, String name,
    CursorFactory factory, int version) {
super(context, name, factory, version);

}

@Override
public void onCreate(SQLiteDatabase arg0) {
arg0.execSQL(CREATE_TABLE_USER);
arg0.execSQL(CREATE_TABLE_STU);

}

    我在MainActivity中

private MyDatabaseHelper myhelper;

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    myhelper = new MyDatabaseHelper(MainActivity.this, "UserDB.db", null, 1);

    myhelper.getWritableDatabase();


    可以用第一张表USER ,但是在第二个Activity中要怎么才能对第二张表STU进行增删改查操作呢 求帮忙

2个回答

就你的需求
private String CREATE_TABLE_USER = "create table USER(" + "username text,"

  • "usermima text," + ")"; 可以简化为 private String CREATE_TABLE_USER = "create table USER(username text,usermima text)";
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!