SQLite Android没有插入数据

时间:2016-03-04 10:04:50

标签: android database sqlite

所以即使我按正确的顺序放置SQLite,我的INSERT INTO contentValues函数也会以错误的顺序插入数据。

这是我的班级:

public class UserInfo extends SQLiteOpenHelper {

    private static final int DATABASE_VERSION = 2;
    private static final String DB_TABLE_NAME = "usersData";
    private static final String USERNAME = "username";
    private static final String DETAILS = "details";
    public static final String DATABASE_NAME = "users.db";
    private static final String DICTIONARY_TABLE_CREATE =
            "CREATE TABLE " + DB_TABLE_NAME + " (" +
                    USERNAME  + " TEXT," + DB_ONE + " TEXT" + " )";

    public ReminderDB(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        Log.d("Database operations", "Database created");
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(DICTIONARY_TABLE_CREATE);
        Log.d("Database operations", "Table created");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + DB_TABLE_NAME );
        onCreate(db);
    }

    public void addReminder(String username, String reminders){
        SQLiteDatabase sqLiteDatabase = this.getWritableDatabase();
        ContentValues contentValues = new ContentValues();
        contentValues.put(USERNAME, username);
        contentValues.put(DETAILS, details);
        sqLiteDatabase.insert(DB_TABLE_NAME, null, contentValues);
    }
}

LogCat错误堆栈:

android.database.sqlite.SQLiteException: table userData has no column named username (code 1): , while compiling: INSERT INTO userData(details,username) VALUES (?,?)

1 个答案:

答案 0 :(得分:1)

  

android.database.sqlite.SQLiteException:table userData没有列   命名用户名(代码1):,编译时:INSERT INTO   userData(详细信息,用户名)VALUES(?,?)

您的本地数据库中有一个名为"userData"的表。但是没有名为"用户名" 的列。

<强>唐&#39;吨

 private static final String DB_TABLE_NAME = "usersData";

<强>不要

 private static final String DB_TABLE_NAME = "userData";

卸载&amp;再次运行

完成 Android SQLite Database Tutorial