Reputation: 499
I am using Android 2.2 with SQLite 3. I am using the query below but it's erroring out with the error log I have pasted.
I am clueless about where I am going wrong.
My Code:
private static final String table_post_natal_care= new String("create table post_natal_care ("+
"number_of_meal text ,"+
"excessive_bleeding text ,"+
"number_of_pads_changed text ,"+
"baby_warm text ,"+
"number_of_times_baby_fed text ,"+
"baby_crying text ,"+
"number_of_times_baby_urinating text ,"+
"mother_temperature text ,"+
"mother_discharge text ,"+
"mother_speaking_pattern text ,"+
"mother_fits text ,"+
"mother_perceives_milk text ,"+
"mother_nipples text ,"+
"mother_skin_color text ,"+
"vagina_tearing text ,"+
"baby_swollen_eyes text ,"+
"baby_weight text ,"+
"baby_temperature text ,"+
"baby_pustules text ,"+
"baby_skin text ,"+
"baby_eyes text ,"+
"baby_feeding text ,"+
"baby_limbs text ,"+
"baby_abdomen text ,"+
"baby_cry text ,"+
"baby_chest text,"+
"baby_umbilicius text,"+
"baby_vommit text"+
")");
LogTrace:
I/iDoc ( 277): returning createContentValues_pnc_visit=Yes
I/Database( 277): sqlite returned: error code = 1, msg = near ")": syntax error
D/dalvikvm( 277): GC_FOR_MALLOC freed 2186 objects / 720424 bytes in 56ms
E/Database( 277): Error inserting =Yes
E/Database( 277): android.database.sqlite.SQLiteException: near ")": syntax error: , while compiling: INSERT INTO post_natal_care() VA
LUES(?);
E/Database( 277): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
E/Database( 277): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
E/Database( 277): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
E/Database( 277): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:80)
E/Database( 277): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:36)
E/Database( 277): at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1145)
E/Database( 277): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1536)
E/Database( 277): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1410)
E/Database( 277): at org.atl.db.DBAdapter.insertPNCVisit(DBAdapter.java:824)
E/Database( 277): at com.accenturelabs.idoc.PostNatalCheck.insertPNCData(PostNatalCheck.java:363)
E/Database( 277): at com.accenturelabs.idoc.PostNatalCheck.access$6(PostNatalCheck.java:360)
E/Database( 277): at com.accenturelabs.idoc.PostNatalCheck$4.onClick(PostNatalCheck.java:149)
E/Database( 277): at android.view.View.performClick(View.java:2408)
E/Database( 277): at android.view.View$PerformClick.run(View.java:8816)
E/Database( 277): at android.os.Handler.handleCallback(Handler.java:587)
E/Database( 277): at android.os.Handler.dispatchMessage(Handler.java:92)
E/Database( 277): at android.os.Looper.loop(Looper.java:123)
E/Database( 277): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/Database( 277): at java.lang.reflect.Method.invokeNative(Native Method)
E/Database( 277): at java.lang.reflect.Method.invoke(Method.java:521)
E/Database( 277): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/Database( 277): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/Database( 277): at dalvik.system.NativeStart.main(Native Method)
Upvotes: 0
Views: 953
Reputation: 67286
Your this error Log.
E/Database( 277): android.database.sqlite.SQLiteException: near ")": syntax error: , while compiling: INSERT INTO post_natal_care() VA
It clearly says that you are having problem in inserting data into your table not in creating. So, check your insert query.
Upvotes: 1
Reputation: 582
I think your string query isn't good. It's not clear to see and I don't see what is primary key of your table and I think you missed ";" at end of query
Some code example like:
private static final String TODOLIST_TABLE_CREATE = "create table TODOLIST"
+" (_id integer primary key autoincrement, "
+"summary text not null, "
+"description text, "
+"categoryid integer REFERENCES CATEGORY(_id), "
+"priority integer, "
+"abdeadline text, "
+"goaldeadline text, "
+"remindab integer, "
+"remindgoal integer);";
Use new line to make your query string clear.
Upvotes: 2