参见英文答案 > Inserting a number as a String into a Text column and SQLite stills removes the leading zero 2个
我的桌子是用.创建的
db.execsql(
"CREATE TABLE periods (" +
" vehicle_id INTEGER KEY," +
" line_id INTEGER KEY," +
" period_id INTEGER PRIMARY KEY AUTOINCREMENT," +
" line_code STRING," +
" sup_code STRING," +
" start_date INTEGER," +
" end_date INTEGER" +
")"
);
插入数据
ContentValues values = new ContentValues();
values.put("vehicle_id",1);
values.put("line_id",2);
values.put("line_code","0406");
values.put("sup_code"," ");
values.put("start_date",1);
values.put("end_date",24);
db.insert("periods",null,values);
但是当我用数据检索数据时
Cursor cPeriods = db.rawQuery("SELECT * FROM periods WHERE vehicle_id=" + vehicleId,null);
System.err.printf("sqlite: ### Get line_code = \"%s\"\n",cPeriods.getString(3));
结果总是“406”
最佳答案
STRING不是有效的sqlite类型,因此line_code使用默认类型INTEGER – 尝试更改CREATE TABLE语句以使用TEXT类型代替STRING.