我使用SQLite在我的应用程序中保存数据。 没有例外,但数据未插入表中。 我得到rowId = -1
有人可以帮助我吗?
我对表的定义是:
private static final String SQL_CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" +
" RESULETID INTEGER PRIMARY KEY AUTOINCREMENT, " +
Constants.COL_1 + " TEXT, " +
Constants.COL_2 + " TEXT, " +
Constants.COL_3 + " TEXT, " +
Constants.COL_4 + " TEXT, " +
Constants.COL_5 + " TEXT, " +
Constants.COL_6 + " TEXT)";
@Override
public void onCreate(SQLiteDatabase db) {
//db.execSQL("CREATE TABLE " + TABLE_NAME + "(ID INTEGER PRIMARY KEY AUTOINCREMENT," + "SCAN_DATE TEXT, ORGAN TEXT, SIDE TEXT, RECOMMENDATION TEXT, CHANGES TEXT)");
db.execSQL(SQL_CREATE_TABLE);
}
我的插入功能是:
public boolean insertData(String username, String date, String address, String phone, String recommendation, String changes) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues= new ContentValues();
contentValues.put(Constants.COL_1, username);
contentValues.put(Constants.COL_2, date);
contentValues.put(Constants.COL_3, address);
contentValues.put(Constants.COL_4, phone);
contentValues.put(Constants.COL_5, recommendation);
contentValues.put(Constants.COL_6, changes);
long newRowId = db.insert(TABLE_NAME, null, contentValues);
Log.e("InsertData", Long.toString(newRowId));
return true;
}