Android studio连接数据库后出现的问题——insert插入问题

Android studio连接数据库后出现的问题——insert插入问题_第1张图片

在别的Activity中使用数据库建表的时候要记得调用一下onCreate方法。DBOpenHelper helper=new DBOpenHelper(this,"menu.db",null,1); SQLiteDatabase db=helper.getWritableDatabase(); helper.onCreate(db);

之前没有添加这句话会导致不能添加任何内容到数据库中。

 

 

建表的时候要注意空格和逗号:

db.execSQL("create table if not exists "+TABLE_NAME+" ("+ID+" integer primary key autoincrement ,"
+USERNAME+" text not null ,"+USERPASS+" text not null ,"+PHONENUM+" integer not null ,"+ADDRESS+"" +
        " text ,"+COMMENT+" text )");

类型integer  text。。之前要有一个空格,不能丢。否则容易造成数据库建表不成功。

你可能感兴趣的:(笔记,android)