SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(MainActivity.this.getString(R.string.db_chat_history), null); db.execSQL("create table if not exists unreaded(FromWho text,Msg text)"); Cursor cursor = db.rawQuery("select * from unreaded", null); if(cursor.moveToFirst() && cursor.getCount() >= 1) { do { sendMsg(cursor.getString(cursor.getColumnIndex("FromWho")),cursor.getString(cursor.getColumnIndex("Msg"))); } while (cursor.moveToNext()); }