为什么主键没有自增长?
代码跟老师的一样啊,为什么主键没有自增长?都是NULL
SQLiteDatabase db = openOrCreateDatabase("user.db",MODE_PRIVATE,null); db.execSQL("create table if not exists usertb (_id integer not null primary key autoincrement,name text not null,age integer,sex text not null)"); db.execSQL("insert into usertb(name,age,sex) values('张三',18,'女')"); db.execSQL("insert into usertb(name,age,sex) values('李四',19,'女')"); db.execSQL("insert into usertb(name,age,sex) values('王五',20,'男')"); Cursor c = db.rawQuery("select * from usertb",null); if(c!=null){ while(c.moveToNext()){ Log.i("info","_id:"+c.getInt(c.getColumnIndex("_id"))); Log.i("info","name:"+c.getString(c.getColumnIndex("name"))); Log.i("info","age:"+c.getInt(c.getColumnIndex("age"))); Log.i("info","sex:"+c.getString(c.getColumnIndex("sex"))); Log.i("info","__________________________________"); } c.close(); } db.close();
打出来的结果ID全是0,navicat 里面看到ID全是null。。
06-12 05:53:30.405 26973-26973/com.geekband.sqllitedemo01 I/info: _id:0
06-12 05:53:30.405 26973-26973/com.geekband.sqllitedemo01 I/info: name:张三
06-12 05:53:30.405 26973-26973/com.geekband.sqllitedemo01 I/info: age:18
06-12 05:53:30.405 26973-26973/com.geekband.sqllitedemo01 I/info: sex:女
06-12 05:53:30.405 26973-26973/com.geekband.sqllitedemo01 I/info: __________________________________
06-12 05:53:30.405 26973-26973/com.geekband.sqllitedemo01 I/info: _id:0
06-12 05:53:30.405 26973-26973/com.geekband.sqllitedemo01 I/info: name:李四
06-12 05:53:30.405 26973-26973/com.geekband.sqllitedemo01 I/info: age:19
06-12 05:53:30.405 26973-26973/com.geekband.sqllitedemo01 I/info: sex:女
06-12 05:53:30.405 26973-26973/com.geekband.sqllitedemo01 I/info: __________________________________
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: _id:0
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: name:王五
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: age:20
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: sex:男
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: __________________________________
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: _id:0
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: name:张三
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: age:18
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: sex:女
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: __________________________________
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: _id:0
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: name:李四
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: age:19
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: sex:女
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: __________________________________
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: _id:0
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: name:王五
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: age:20
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: sex:男
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: __________________________________
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: _id:0
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: name:张三
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: age:18
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: sex:女
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: __________________________________
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: _id:0
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: name:李四
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: age:19
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: sex:女
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: __________________________________
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: _id:0
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: name:王五
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: age:20
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: sex:男
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: __________________________________
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: _id:0
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: name:张三
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: age:18
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: sex:女
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: __________________________________
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: _id:0
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: name:李四
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: age:19
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: sex:女
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: __________________________________
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: _id:0
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: name:王五
06-12 05:53:30.406 26973-26973/com.geekband.sqllitedemo01 I/info: age:20
06-12 05:53:30.407 26973-26973/com.geekband.sqllitedemo01 I/info: sex:男
06-12 05:53:30.407 26973-26973/com.geekband.sqllitedemo01 I/info: __________________________________
06-12 05:53:30.493 26973-27023/com.geekband.sqllitedemo01 D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: