0

Trying to insert data in database from edittext in android but data is not inserting.

MY CODE --

ContentValues values= new ContentValues();
values.put(KEY_EMAIL, GlobalVar.email);
values.put(KEY_NAME, GlobalVar.name);
myDataBase.insert(MY_EMP, null,values);

MY LOG CAT

04-10 09:50:20.121: E/running(280): create database called
04-10 09:50:20.121: E/running(280): chek database called
04-10 09:50:20.121: E/running(280): chek database try block called
04-10 09:50:20.171: E/running(280): create database called try block
04-10 09:50:20.191: E/running(280): copy database called
04-10 09:50:20.211: E/running(280): open data successfull
04-10 09:50:50.720: W/KeyCharacterMap(280): No keyboard for id 0
04-10 09:50:50.720: W/KeyCharacterMap(280): Using default keymap: /system/usr/keychars/qwerty.kcm.bin

`

3
  • 1
    It seems that you're missing the relevant log output because there's no stack trace. Is this code throwing an exception? Commented Apr 10, 2012 at 4:33
  • please provide some more information from your log file like @Tyler Treat mentioned. Commented Apr 10, 2012 at 4:34
  • How can you say data not inserted in SQLite..have you checked the database from data folder in any SQLite browser? Commented Apr 10, 2012 at 5:12

2 Answers 2

2

If you don't supply all the required column data (i.e. data for all columns that don't have a default value, accept null, or are auto-incrementing), then the insert command will fail.

However, if insert fails, it doesn't throw an exception. It just returns -1.

Check the result of your insert call, or better yet, change the call to

myDataBase.insertOrThrow(MY_EMP, null,values);

and then check the logs for the exception message assuming there is one.

Sign up to request clarification or add additional context in comments.

Comments

1

It seems u r missing the required parameters in myDataBase.insert(MY_EMP, null,values); it should be myDataBase.insert("Table Name ", "First column name ",cv);

Try this

1 Comment

This is not necessarily correct. The second parameter is the null column hack (and it's certainly not required), so unless he's inserting a completely empty row, which I don't think he is, this is wrong.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.