0

I try to use EditText to save database in SQLiteOpenHelper.

When i add the values on the function , it throws IllegalStateException on my execSQL function.

I don't have any idea about it, any help will be grateful.

it's my create database code:

@Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        getWritableDatabase().execSQL("CREATE TABLE blood " +
                "(_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
                "bloodvalue VARCHAR , " +
                "eattime VARCHAR, " +
                "blooddate DATETIME NOT NULL)");
    }

it's my add button function:

sendBlood = (Button) findViewById(R.id.sendBlood);
        sendBlood.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String bloodSugar = editBloodSugar.getText().toString();
                String bloodEatTime = editBloodEatTime.getText().toString();
                int bloodDate = Integer.parseInt(editBloodDate.getText().toString());

                ContentValues values = new ContentValues();
                values.put("bloodvalue", bloodSugar);
                values.put("eattime", bloodEatTime);
                values.put("blooddate", bloodDate);
                long id = sqlForBloodSugar.getWritableDatabase().insert("blood", null, values);
                Log.d("ADD", id + "");
            }
        });
2
  • stacktrace please Commented Jan 15, 2017 at 9:22
  • i got the solution , thanks for attention. Commented Jan 15, 2017 at 9:49

1 Answer 1

1

Use sqLiteDatabase.execSQL() instead of getWritableDatabase().execSQL()

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

1 Comment

You are welcome. Not shame to not know, shame to not ask

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.