【问题标题】:Problems inserting to database for android app为android应用程序插入数据库的问题
【发布时间】:2013-08-16 21:45:25
【问题描述】:

当我尝试插入我的数据库时,我不断收到下面列出的错误:

08-14 11:50:21.455: E/SQLiteLog(27688): (1) table exercises has no column named reps
08-14 11:50:21.495: E/SQLiteDatabase(27688): Error inserting reps=4 title=  BarBell Curls weight=4 notes=db date=August-14-2013
08-14 11:50:21.495: E/SQLiteDatabase(27688): android.database.sqlite.SQLiteException: table exercises has no column named reps (code 1): , while compiling: INSERT INTO exercises(reps,title,weight,notes,date) VALUES (?,?,?,?,?)

这是我的创作声明:

//数据库创建sql语句

private static final String DATABASE_CREATE = "create table " + DATABASE_TABLE + " (" + KEY_ROWID + " integer primary key autoincrement, "
                                            + KEY_TITLE + " text not null, "
                                            + DATE_SELECTED + " text not null, "
                                            + WEIGHT_INPUT + " text not null, "
                                            + REPS_INPUT + " text not null, "
                                            + KEY_BODY + " text not null" + ");";

//插入行的方法

public long createExercise(String title, String date, String weight, String reps, String body)
{
    ContentValues initialValues = new ContentValues();
    initialValues.put(KEY_TITLE, title);
    initialValues.put(DATE_SELECTED, date);
    initialValues.put(WEIGHT_INPUT, weight);
    initialValues.put(REPS_INPUT, reps);
    initialValues.put(KEY_BODY, body);
    return myDatabase.insert(DATABASE_TABLE, null, initialValues);
}

我知道我只是错过了一些简单的东西,任何帮助将不胜感激! 干杯

【问题讨论】:

  • 您之前是否有时创建过这个数据库,后来又添加了 REPS_INPUT?如果是,则数据库仍然存在,如果您没有卸载应用程序(或从您保存它的位置删除数据库)。尝试从零开始,删除您的应用并重新安装。如果数据库存储在外部存储上,则删除数据库
  • 你在使用SQLiteOpenHelper吗?如果是这样,您是否在最初创建表后将reps 列添加到创建字符串?
  • 我没有正确打开数据库。我将我的 open 添加到构造函数中,并且不再出现任何错误。
  • 我还没有让它正确显示,但这是另一个问题。感谢您的建议。

标签: android database sqlite compiler-errors insertion


【解决方案1】:

SQLite 错误指出,“表练习没有名为 reps 的列。”

【讨论】:

  • 是的,我认为这很明显,但你的回答并没有回答为什么会这样。
  • 可能在创建表时有错字。只是想把那个人指向正确的方向。
  • 我这里没有打开:public CalendarDBAdapter(Context ctx) { this.mCtx = ctx;打开(); }
猜你喜欢
  • 2019-06-14
  • 1970-01-01
  • 1970-01-01
  • 2019-11-18
  • 2016-04-17
  • 1970-01-01
  • 2021-08-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多