I have an app that gets all the data from the sqlite database and converts it into JSON, but I was wondering how would I be able to do it if I only want to get the data of specific columns?
This is the code I use to get all the data from the SQLite databse and convert it to JSON:
Cursor data = db.getCartItems();
orderNameArray = new JSONArray();
data.moveToFirst();
while(data.isAfterLast() == false)
{
int totalColumn = data.getColumnCount();
orderNameObject = new JSONObject();
for (int i = 0; i < totalColumn; i++)
{
try {
orderNameObject.put(data.getColumnName(i), data.getString(i));
} catch (JSONException e) {
e.printStackTrace();
}
}
orderNameArray.put(orderNameObject);
data.moveToNext();
}
data.close();
Thanks in advance for all the insights or help in advance! :D
If you want to fetch only selected fields of table, then use the following query:
SELECT Coulmn1, Coulmn2, Coulmn3 FROM TABLENAME;
or u want all data
SELECT * FROM TABLENAME;
for more info https://www.tutorialspoint.com/sqlite/sqlite_select_query.htm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With