0

我已将产品名称保存在Sqllite 数据库的一列中。现在已经保存了很多产品名称,我需要将所有产品名称发送到 Web 服务。例如 egg、briyani、idly。我已经在其中使用了此代码,Sqllite但未附加字符串。我在此代码下面提到了:

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();
     }
4

3 回答 3

2
if (mCursor.moveToFirst()) {
 buf.append(mCursor.getString(0)+",");
}

问题是你没有迭代你的结果。改为这样做:

while(mCursor.moveToNext()) {

 buf.append(mCursor.getString(mCursor.getColumnIndex(column_name))+",");

}
于 2013-04-01T08:39:39.107 回答
0

您的代码很好,但您伪造:db.getWritableDatabase();getreadableDatabase()

我修改了你的代码这里DBController是我的课public class DBController extends SQLiteOpenHelper

所以你的代码将是..

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();
    }
于 2013-04-01T08:54:01.460 回答
-1

在这里做个小改动,

而不是这条线,

String query = "select  "+column_name+" From " + TABLErestaurant;

试试这条线

String query = "select  * From " + TABLErestaurant;
于 2013-04-01T08:35:42.693 回答