Error compiling insert into: No column named ID

痞子三分冷 提交于 2019-12-25 08:57:43

问题


Been testing some answers found but still no effect. What am I missing? Please see below.

String createTableCommand = "CREATE TABLE " + TABLE_NAME + "("
        + COL_USER_ID +" INTEGER PRIMARY KEY,"
        + COL_USER_FULL_NAME + " TEXT NOT NULL,"
        + COL_USER_PASSWORD + " TEXT NOT NULL)";

 @Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL(createTableCommand);
}

public void insertUsers(User user){
    SQLiteDatabase db = this.getReadableDatabase();
    ContentValues values = new ContentValues();
    values.put(COL_USER_ID,user.getid());
    values.put(COL_USER_FULL_NAME,user.getUserFullName());
    values.put(COL_USER_PASSWORD,user.getPassword());
    db.insert(TABLE_NAME,"",values);
    Log.d("Inside insertUsers(): ","INSERTED "+user.getid() + " " +user.getUserFullName() + " " +user.getPassword());
}
Error: E/SQLiteLog: (1) table User has no column named ID
10-30 21:04:09.791 15860-15860/com.bustracker.usc.uscbt E/SQLiteDatabase: Error inserting ID=15200002 PASSWORD=shansay FULLNAME=Shansay
android.database.sqlite.SQLiteException: table User has no column named ID (code 1): , while compiling: INSERT INTO User(ID,PASSWORD,FULLNAME) VALUES (?,?,?)
    at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
    at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
    at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
    at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
    at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
    at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1472)
    at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1343)
    at com.bustracker.usc.uscbt.com.usc.tc.dbhandler.UserDbHandler.insertUsers(UserDbHandler.java:62)
    at com.bustracker.usc.uscbt.com.bustracker.com.uscbt.model.UserCRUD$1.onClick(UserCRUD.java:39)
    at android.view.View.performClick(View.java:5637)
    at android.view.View$PerformClick.run(View.java:22429)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6119)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

来源:https://stackoverflow.com/questions/47016138/error-compiling-insert-into-no-column-named-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!