totoro totoro - 8 months ago 55
Java Question

Android sqlite JOIN query with the select columns given by String[]

I have string array with columns I want to select:

String[] columns = {"col1", "col2", "col3"};

The columns might change in the future, but will always be a subset of available columns.

I cannot find a
API that lets me pass this array as columns. The only solution I have so far is to just string join the columns with
as separator and add it into my query string and perform a

Is there a better solution?


The query is a


The query() methods in SQLiteDatabase take in a String[] columns argument which seems to be the thing what you are looking for.

Raw queries with string joining with , works, too, and that's basically what query() does under the hood.

Oh, I forgot to mention it involves a JOIN too

Then your best options is probably rawQuery() with SQL you're building yourself. Android SQLite wrapper APIs are really not too flexible.