“表X没有名为Y的列”错误将数据插入SQLite数据库

时间:2014-10-08 20:37:10

标签: android-sqlite

我收到了这个错误:

10-08 22:23:06.635: E/SQLiteLog(20613): (1) table mytable has no column named GPS
10-08 22:23:06.645: E/SQLiteDatabase(20613): Error inserting AppName=Ster-Kinekor GPS=false Time=22:23:6 Network=true Date=2014/10/08
10-08 22:23:06.645: E/SQLiteDatabase(20613): android.database.sqlite.SQLiteException: table mytable has no column named GPS (code 1): , while compiling: INSERT INTO mytable(AppName,GPS,Time,Network,Date) VALUES (?,?,?,?,?)

我已经检查了人们为了得到这个错误而犯的所有正常的愚蠢错误,很确定我没有逗号或间距错误。请帮我找到错误,非常感谢任何帮助

以下是相关代码:

public static final String KEY_ROWID = "id";
public static final String KEY_AppName = "AppName";
public static final String KEY_Date = "Date";
public static final String KEY_Time = "Time";
public static final String KEY_Gps = "GPS";
public static final String KEY_Network = "Network";

... ... ...

public void onCreate(SQLiteDatabase arg0) {

    try{
        arg0.execSQL("create table if not exists mytable ("
                + "id integer primary key autoincrement, "
                + KEY_AppName+" text not null," 
                + KEY_Date+" text,"
                + KEY_Time+ " text," 
                + KEY_Gps+" text,"
                + KEY_Network+" text"
                +");");

    } catch (Exception e){
        e.printStackTrace();
    }
}


public void insertRecord(LocationUsageDB lb)
    {
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues initialValues = new ContentValues();//
        initialValues.put(KEY_AppName, lb.AppName); //just do the same for any other columns 
        initialValues.put(KEY_Date, lb.Date);
        initialValues.put(KEY_Time, lb.Time);
        initialValues.put(KEY_Gps, lb.Gps);
        initialValues.put(KEY_Network, lb.Network);

        db.insert(TABLE_NAME, null, initialValues);
        db.close();
    }

我在这里发送值:

mydb.insertRecord(new LocationUsageDB(foregroundTaskAppName, date, t.hour+":"+t.minute+":"+t.second, "false", "true"  ));

0 个答案:

没有答案