Inserting data into an sqlite database [duplicate]

我与影子孤独终老i 提交于 2019-12-13 10:14:28

问题


Possible Duplicate:
inserting data in sqlite database errors

I am trying to get the answers from a form in an application with android. Everything is fine with the activity , but the problem is that I can't get the answers to be inserted in the database .

and here is the error i get in the logcat :

        07-31 02:34:44.092: E/Database(398): Error inserting REP3=oui REP4=non REP1=oui REP2=oui LONGITUDE=0.0 ZONE=rabat REP5=oui LATITUDE=0.0
        07-31 02:34:44.092: E/Database(398): android.database.sqlite.SQLiteException: table Appreciation has no column named REP4: , while compiling: INSERT INTO Appreciation(REP3, REP4, REP1, REP2, LONGITUDE, ZONE, REP5, LATITUDE) VALUES(?, ?, ?, ?, ?, ?, ?, ?);
        07-31 02:34:44.092: E/Database(398):    at android.database.sqlite.SQLiteProgram.native_compile(Native Method)
        07-31 02:34:44.092: E/Database(398):    at android.database.sqlite.SQLiteProgram.compile(SQLiteProgram.java:110)
        07-31 02:34:44.092: E/Database(398):    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:59)
        07-31 02:34:44.092: E/Database(398):    at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:41)
        07-31 02:34:44.092: E/Database(398):    at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1026)
        07-31 02:34:44.092: E/Database(398):    at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1412)
        07-31 02:34:44.092: E/Database(398):    at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1285)
        07-31 02:34:44.092: E/Database(398):    at com.stage.sondage.SurveyAdapter.insertAppreciation(SurveyAdapter.java:75)
        07-31 02:34:44.092: E/Database(398):    at com.stage.sondage.Questionnaire$1.onClick(Questionnaire.java:64)
        07-31 02:34:44.092: E/Database(398):    at android.view.View.performClick(View.java:2364)
        07-31 02:34:44.092: E/Database(398):    at android.view.View.onTouchEvent(View.java:4179)
        07-31 02:34:44.092: E/Database(398):    at android.widget.TextView.onTouchEvent(TextView.java:6540)
        07-31 02:34:44.092: E/Database(398):    at android.view.View.dispatchTouchEvent(View.java:3709)
        07-31 02:34:44.092: E/Database(398):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
        07-31 02:34:44.092: E/Database(398):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
        07-31 02:34:44.092: E/Database(398):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
        07-31 02:34:44.092: E/Database(398):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
        07-31 02:34:44.092: E/Database(398):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
        07-31 02:34:44.092: E/Database(398):    at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
        07-31 02:34:44.092: E/Database(398):    at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
        07-31 02:34:44.092: E/Database(398):    at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
        07-31 02:34:44.092: E/Database(398):    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
        07-31 02:34:44.092: E/Database(398):    at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
        07-31 02:34:44.092: E/Database(398):    at android.os.Handler.dispatchMessage(Handler.java:99)
        07-31 02:34:44.092: E/Database(398):    at android.os.Looper.loop(Looper.java:123)
        07-31 02:34:44.092: E/Database(398):    at android.app.ActivityThread.main(ActivityThread.java:4363)
        07-31 02:34:44.092: E/Database(398):    at java.lang.reflect.Method.invokeNative(Native Method)
        07-31 02:34:44.092: E/Database(398):    at java.lang.reflect.Method.invoke(Method.java:521)
        07-31 02:34:44.092: E/Database(398):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
        07-31 02:34:44.092: E/Database(398):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
        07-31 02:34:44.092: E/Database(398):    at dalvik.system.NativeStart.main(Native Method)

it says that the error is in :

        7-31 02:34:44.092: E/Database(398): android.database.sqlite.SQLiteException: table Appreciation has no column named REP4: , while compiling: INSERT INTO Appreciation(REP3, REP4, REP1, REP2, LONGITUDE, ZONE, REP5, LATITUDE) VALUES(?, ?, ?, ?, ?, ?, ?, ?);

and also in

        07-31 02:34:44.092: E/Database(398):    at com.stage.sondage.SurveyAdapter.insertAppreciation(SurveyAdapter.java:75)
        07-31 02:34:44.092: E/Database(398):    at com.stage.sondage.Questionnaire$1.onClick(Questionnaire.java:64)

which is

       survey.insertAppreciation(appreciation); //in Questionnaire.java
and 
            return bdd.insert(APPRECIATION_TABLE_NAME, null, values);// in survey adapter

it says that the COLUMN REP4 does not exist in the table Appreciation however i made sure that this COLUMN exists while declaring the class Appreciation the class that extends OpenHelper and the method where i insert the information in the table

thank u for your help


回答1:


You are missing a space , after the column name of REP4 and before TEXT NOT NULL:
Your code is:

 private static final String REQUETE_CREATION_BDD = "CREATE TABLE "+   APPRECIATION_TABLE_NAME + " (" + COLUMN_IDAPPRECIATION
        + " INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_ZONE
        + " TEXT NOT NULL, " +COLUMN_LATITUDE
        + " DOUBLE NOT NULL, " +COLUMN_LONGITUDE
        + " DOUBLE NOT NULL, " + COLUMN_REP1 + " TEXT NOT NULL, "
        + COLUMN_REP2 + " TEXT NOT NULL,"+COLUMN_REP3 + " TEXT NOT NULL,"
        +COLUMN_REP4+"TEXT NOT NULL,"+COLUMN_REP5 +" TEXT NOT NULL);";

And it should be:

private static final String REQUETE_CREATION_BDD = "CREATE TABLE "+ APPRECIATION_TABLE_NAME + " (" + COLUMN_IDAPPRECIATION
        + " INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_ZONE
        + " TEXT NOT NULL, " +COLUMN_LATITUDE
        + " DOUBLE NOT NULL, " +COLUMN_LONGITUDE
        + " DOUBLE NOT NULL, " + COLUMN_REP1 + " TEXT NOT NULL, "
        + COLUMN_REP2 + " TEXT NOT NULL,"+COLUMN_REP3 + " TEXT NOT NULL,"
        +COLUMN_REP4+" TEXT NOT NULL,"+COLUMN_REP5 +" TEXT NOT NULL);";


来源:https://stackoverflow.com/questions/11733236/inserting-data-into-an-sqlite-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!