Reputation: 73
I have saved product name in one column in Sqllite
database .Lot of product name are already saved there now, I need to get all product name sent it to web service.For example egg, briyani, idly.
I have used it this code in Sqllite
but String is not append.I have mention below this code:
public String fetchMyRowid(String column_name)
{
String query = "select "+column_name+" From " + TABLErestaurant;
mCursor =db.rawQuery(query, null);
StringBuffer buf = new StringBuffer();
if (mCursor.moveToFirst()) {
buf.append(mCursor.getString(0)+",");
}
return buf.toString();
}
Upvotes: 0
Views: 934
Reputation: 18978
your code is fine but you forgate: db.getWritableDatabase();
or getreadableDatabase()
i have modify your code here DBController
is my class public class DBController extends SQLiteOpenHelper
so your code ll be..
public String fetchMyRowid(String column_name, DBController db) {
String query = "SELECT " + column_name + " FROM " + TABLErestaurant;
SQLiteDatabase dd = db.getWritableDatabase();
cursor = dd.rawQuery(query, null);
StringBuffer buf = new StringBuffer();
if(cursor.getCount() > 0 || cursor != null){
do {
Log.e("name--->", "" + cursor.getString(0));
buf.append(cursor.getString(0) + ",");
} while (cursor.moveToNext());
Log.e("name---> buffeer-->", "" + buf);
}
return buf.toString();
}
Upvotes: 0
Reputation: 8304
if (mCursor.moveToFirst()) {
buf.append(mCursor.getString(0)+",");
}
The problem is you're not iterating through your results. Do this instead:
while(mCursor.moveToNext()) {
buf.append(mCursor.getString(mCursor.getColumnIndex(column_name))+",");
}
Upvotes: 2
Reputation: 29632
Just make a small change here,
instead of this line ,
String query = "select "+column_name+" From " + TABLErestaurant;
try this line
String query = "select * From " + TABLErestaurant;
Upvotes: -1