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 (?, ?, ?, ?, ?)
 

aeric

Expert
Licensed User
Longtime User
Isn't it should be written as follow?
INSERT INTO tablename (field1, field2, field3, field4, field5) VALUES (?, ?, ?, ?, ?)
 
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
Cookies are required to use this site. You must accept them to continue using the site. Learn more…