android中的sqlite数据库中的列未被创建

时间:2017-07-04 18:26:08

标签: android sqlite android-sqlite

我已经创建了一个表BookDb,但创建列的查询没有在onCreate()类的DbHelper方法中执行,该方法是SQLiteOpenHelper()的扩展名。

这是课程DbHlelper

public class DbHelper extends SQLiteOpenHelper {

    public DbHelper(Context context) {
        super(context, Contract.FeedEntry.TABLE_NAME, null, 1);
    }
    @Override
    public void onCreate(SQLiteDatabase db) {
        final String SQL_CREATE_ENTRIES =
                "CREATE TABLE IF NOT CREATED BookDb( id INTEGER PRIMARY KEY, " +
                        "BookName TEXT, " +
                        "Author TEXT, " +
                        "IssuedOn TEXT, " +
                        "DueDate TEXT, " +
                        "Fine TEXT, " +
                        "Totalfine TEXT )" ;
        db.execSQL(SQL_CREATE_ENTRIES);
        Log.v("Create","TABLE CREATED!!!!!!!!!!");
    }

以下是我插入值的主要活动中的代码:

void SaveEntry() {
    DbHelper db = new DbHelper(this);

    data = db.getWritableDatabase();
    db.onOpen(data);
    //db.onCreate(data);

    ContentValues values = new ContentValues();
    values.put(Contract.FeedEntry.COLUMN_NAME_Bname, bname);
    values.put(Contract.FeedEntry.COLUMN_NAME_AUTHOR, authname);
    values.put(Contract.FeedEntry.COLUMN_NAME_Issue, issuedate);
    values.put(Contract.FeedEntry.COLUMN_NAME_DUE, dueafter);
    values.put(Contract.FeedEntry.COLUMN_NAME_FINE_PER_DAY, fine);

    long rowId = data.insert(Contract.FeedEntry.TABLE_NAME, null, values);
}

这是合同类:

public class Contract {

    private Contract() {}

    /* Inner class that defines the table contents */
    public static class FeedEntry implements BaseColumns {
        public static final String TABLE_NAME = "BookDb";
        public static final String COLUMN_NAME_Bname = "BookName";
        public static final String COLUMN_NAME_AUTHOR="Author";
        public static final String COLUMN_NAME_Issue = "IssuedOn";
        public static final String COLUMN_NAME_DUE="DueDate";
        public static final String COLUMN_NAME_FINE_PER_DAY="Fine";
        public  static final String COLUMN_NAME_TFINE="TotalFine";
    }
}

日志显示::

  

E / SQLiteLog:(1)表BookDb没有名为Fine的列    E / SQLiteDatabase:错误插入Fine = nc IssuedOn = vz Author = jx DueDate = bz BookName = va                                                                                 android.database.sqlite.SQLiteException:table BookDb没有名为Fine(code 1)的列:,编译时:INSERT INTO BookDb(Fine,IssuedOn,Author,DueDate,BookName)VALUES(?,?,?,?,?)                                                                                     在android.database.sqlite.SQLiteConnection.nativePrepareStatement(本机方法)                                                                                     在android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)                                                                                     在android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)                                                                                     在android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)                                                                                     在android.database.sqlite.SQLiteProgram。(SQLiteProgram.java:58)                                                                                     在android.database.sqlite.SQLiteStatement。(SQLiteStatement.java:31)                                                                                     在android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1469)                                                                                     在android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1341)                                                                                     at com.example.shaily.librarian.AddBook.SaveEntry(AddBook.java:219)                                                                                     在com.example.shaily.librarian.AddBook.onClick(AddBook.java:91)                                                                                     在android.view.View.performClick(View.java:4791)                                                                                     在android.view.View $ PerformClick.run(View.java:19884)                                                                                     在android.os.Handler.handleCallback(Handler.java:739)                                                                                     在android.os.Handler.dispatchMessage(Handler.java:95)                                                                                     在android.os.Looper.loop(Looper.java:135)                                                                                     在android.app.ActivityThread.main(ActivityThread.java:5268)                                                                                     at java.lang.reflect.Method.invoke(Native Method)                                                                                     在java.lang.reflect.Method.invoke(Method.java:372)                                                                                     在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:902)                                                                                     在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697)

0 个答案:

没有答案