Android Question MySQL Insert Error

Richard Goh

Active Member
Licensed User
Longtime User
Hi,
I got the below error when inserting record into the table. The table is created properly and with the correct column name in it. I had checked the table and match the column name as well. I also created others tables the same ways in the same db but only this table having this problem. Any advice on this? Thanks in advance.

android.database.sqlite.SQLiteException: table tablename has no column named field3 (code 1): , while compiling: INSERT INTO [field1] ([field2], [field3], [field4], [field5]) VALUES (?, ?, ?, ?, ?)
 

DonManfred

Expert
Licensed User
Longtime User
there is no field with the name field3 in the table
 
Upvote 0

Richard Goh

Active Member
Licensed User
Longtime User
Sorry, there was a typo of the insert statement above. It should be INSERT INTO ([field1], [field2], [field3], [field4], [field5]) Value (?, ?, ?, ? ,?).
I had checked the table creation. It's fined. But somehow even I rename the table or field name it's still gave the insert error.
 
Upvote 0

gz7tnn

Member
Licensed User
Longtime User
Another suggestion I have is to test your insert statement in another program.
Because of subtle differences between different databases (MySQL / SQLite / Oracle / MSAccess/ etc) I tend to write and test any sql code in the actual database environment and copy/paste the result into my final program.

Once I have tested that it works I can then substitute the final values with the variables and include it in my final project and that way I have I high certainty that the code will work.
That approach also means I do not have to go through the cycle of - code / compile / release / test / fail / re-code / .......
Again, just a suggestion.
 
Upvote 0
Top