Android insert into sqlite database?

Your query is invalid because you are providing 2 values for 3 columns. Your raw query should look like: sql = "INSERT INTO table1 (field1, field2) " + "VALUES (" + field_one + ", " + field_two + ") although your schema contains three fields. By the way, you can see the log to see the actual error reporting from sqlite.

Your query is invalid because you are providing 2 values for 3 columns. Your raw query should look like: sql = "INSERT INTO table1 (field1, field2) " + "VALUES (" + field_one + ", " + field_two + ")"; although your schema contains three fields. By the way, you can see the log to see the actual error reporting from sqlite.

I cleaned up the code some and accidentally removed the third field in the values section. Good catch though. – Blather Apr 12 '10 at 0:18.

Since it is a string values you forgot "'" to add...this query will surely work, I tested sql = "INSERT INTO table1 (field1, field2) " + "VALUES ('" + field_one + "', '" + field_two + "').

1 for help Maddy J – ekjyot Oct 21 at 10:20.

I changed my code to use myDataBase.insert() instead of rawQuery() and it's working. I'm not sure why the actual sql query didn't work though, so if anyone can shed some light on that I'd still appreciate it.

3 If what you posted is the exact query, it's because you're specifying 3 fields but only passing 2 values. – tadamson Apr 11 '10 at 6:49 10 rawQuery() is for queries. An INSERT statement is not a query.

If you want to execute raw SQL that does not return a result set, use execSQL(). – CommonsWare Apr 11 '10 at 10:21 Ah, execSql() is what I needed then. And yes, I was passing 3 values in my code but it got lost in the code cleanup when I pasted it over here.

Thanks! @CommonsWare, if you post that as an answer here I will give you credit for solving it. – Blather Apr 12 '10 at 0:19.

I have a database for the Android application I'm currently working on (Android v1.6) and I just want to insert a single record into a database table. The myDataBase variable is a SQLiteDatabase object that can select data fine from another table in the schema. The saving appears to work fine (no errors in LogCat) but when I copy the database from the device and open it in sqlite browser the new record isn't there.

I also tried manually running the query in sqlite browser and that works fine. The table schema for table1 is _id, field1, field2, field3. Any help would be greatly appreciated.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions