简体   繁体   English

将错误插入数据库表

[英]Insertion error into a database table

I'm really struggling to sort some issues inserting time and dates into a table in my database that dosent seem to excist!. 我真的很难解决将时间和日期插入数据库中似乎存在的表中的一些问题!

I asked a question on the 'no such table' issue but didn't get an answer that sorted this issue and circumstances have changed. 我问了一个关于“没有这样的桌子”问题的问题,但没有得到对这个问题进行分类的答案,情况也发生了变化。

Really hoping someone can help me as i cant go forward until i solve this. 真的希望有人能帮助我,因为我无法解决这个问题。

Edit: 编辑:

Does the logcat show im trying to insert before creating the table? logcat是否在创建表之前显示im正在尝试插入?

Heres my Logcat error: 这是我的Logcat错误:

01-20 23:38:24.128: E/Database(287): Error inserting app_time=00114200T000000Europe/Dublin(0,0,0,-1,0) app_alarm=false app_date=2013-01-24 app_name=gggg app_comments=a app_type=Business
01-20 23:38:24.128: E/Database(287): android.database.sqlite.SQLiteException: no such table: appointmentsTable: , while compiling: INSERT INTO appointmentsTable(app_time, app_alarm, app_date, app_name, app_comments, app_type) VALUES(?, ?, ?, ?, ?, ?);

Is it a case of this data cannot be inserted as there is no table? 是否存在这种情况,因为没有表,因此无法插入该数据? I have no idea why I cannot create a table. 我不知道为什么不能创建表。 Im also confused as to why the values passed are '?' 我还对为什么传递的值是“?”感到困惑

Again here is my OnCreate method: 再次这是我的OnCreate方法:

@Override
    public void onCreate(SQLiteDatabase db) {


        db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" +
                KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                KEY_NAME + " TEXT NOT NULL, " +
                KEY_TEL + " TEXT NOT NULL, " +
                KEY_EMAIL + " TEXT NOT NULL, " +
                KEY_COMMENTS + " TEXT NOT NULL);"

                );

        db.execSQL("CREATE TABLE " + DATABASE_TABLEAPP + " (" +
                KEY_ROWAPPID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                KEY_NAMEAPP + " TEXT NOT NULL, " +
                KEY_TYPEAPP + " TEXT NOT NULL, " +
                KEY_TIMEAPP + " TEXT NOT NULL, " +
                KEY_DATEAPP + " TEXT NOT NULL, " +
                KEY_COMMENTAPP + " TEXT NOT NULL, " +
                KEY_ALARM + " BOOLEAN NOT NULL);"

                );      
    }

My insertion method: 我的插入方法:

    public void createAppointmentEntry(String nameApp, String typeApp, Time timeApp, Date dateApp ,String commentApp, Boolean onOrOff) {



        ContentValues cv = new ContentValues();
        cv.put(KEY_NAMEAPP, nameApp);
        cv.put(KEY_TYPEAPP, typeApp);
        cv.put(KEY_TIMEAPP, timeApp.toString());
        cv.put(KEY_DATEAPP, dateApp.toString());
        cv.put(KEY_COMMENTAPP, commentApp);
        cv.put(KEY_ALARM, onOrOff);
        ourDatabase.insert(DATABASE_TABLEAPP, null, cv);

    }

Do you see how you have your data types as " TEXT NOT NULL "? 您是否看到数据类型为“ TEXT NOT NULL”? Try changing the "app_time" column to just " TEXT, " and increase the database version. 尝试将“ app_time”列更改为“ TEXT”,然后增加数据库版本。 Also, try downloading SQLite Viewer so that you can get a visual idea of what your db actually looks like and if the column exists. 另外,请尝试下载SQLite Viewer,以便直观了解数据库的实际外观以及该列是否存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM