将数据插入SQLite数据库 [英] Inserting data into an sqlite database
问题描述
可能重复:结果
<一href=\"http://stackoverflow.com/questions/11716447/inserting-data-in-sqlite-database-errors\">inserting在SQLite数据库错误的数据
我想从一个形式问题的答案在与Android的应用程序。一切正常的活动,但问题是,我不能在数据库中插入的答案。
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 .
和这里是我的错误中得到logcat中:
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)
它说,错误是:
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(?, ?, ?, ?, ?, ?, ?, ?);
和,可以在
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)
这是
survey.insertAppreciation(appreciation); //in Questionnaire.java
and
return bdd.insert(APPRECIATION_TABLE_NAME, null, values);// in survey adapter
它说,该列REP4不表鸭preciation存在的,但是我确信,虽然声明类鸭preciation扩展OpenHelper和方法,其中我插入信息的类此列存在在表
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
感谢ü的帮助
推荐答案
您缺少空间,REP4的列名后前文字NOT NULL
:
您code是:
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);";
和它应该是:
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);";
这篇关于将数据插入SQLite数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!