0

Here is the code, by this I can retrieve all the columns data from the database. But the problem is that now I want to retrieve only one column, that is my requirement.link1st link 2nd link3rd

word_list = new ArrayList<>(); SQLiteDatabase sd = mydb.getWritableDatabase(); Cursor cursor = sd.query("stickerstable",null, null, null, null, null, null); if (cursor.moveToFirst()){ do{ word_list.add(new data_items( cursor.getInt(cursor.getColumnIndex(ID)), cursor.getString(cursor.getColumnIndex(STICKER_AUTHOR)), cursor.getString(cursor.getColumnIndex(STICKER_NAME) ))); }while (cursor.moveToNext()); cursor.close(); sd.close(); } 

1 Answer 1

0

You can use rawQuery instead of query

Cursor cursor = sd.rawQuery("SELECT YOUR_COLUMN FROM stickerstable",null); 

replace YOUR_COLUMN with the name of column you want to retrieve you can even use your Constants like this

Cursor cursor = sd.rawQuery("SELECT " + ID + " FROM stickerstable",null); 

or a better way to use String.format

Cursor cursor = sd.rawQuery(String.format("SELECT %s FROM stickerstable", ID),null); 

UPDATE

you can use query and specify the column in the second argument

Cursor cursor = sd.query("stickerstable",new String[]{ID}, null, null, null, null, null); 

when you pass null means get all columns

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

5 Comments

thanks for your response. in main activity retrieve two columns, name sticker author and sticker name, working fine . but if in 2nd activity i insert image in the sqlite and that image also show in the mainActivity list . what can i do.
actually i retrieve only two columns from database, but if insert image in database in 2nd activity it also show in mainActivity list.
i tried your code it wokings for retrieve all data and the image also.. but it cannot solve my problems
Sorry i didn't understand you, Can you update your question with more details and post more code
your Code is good for understanding , that's why i upvote your answer.. thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.