SQLite 取出內容

2011.04.24 03:01PM
SQLite 取出內容

在程式中我用rawQuery來執行一段sql語法,但是傳回一個cursor物件

請問我要如何取出這段語法所截取的內容呢?(把第一筆的欄位內容取出來,只有一個欄位而以憂:D)

1 則回應

  •         String StrSQL = null;

     

            

     

                   

     

            StrSQL ="select code,product,count(*) from recordlist group by code,product";

     

            Cursor c  = null;    

     

            try{

     

                c= db.rawQuery(StrSQL,null);

     

            } catch (Exception ex){

     

                Log.d("Result","SQL Error");

     

                return;

     

            }        

     

            if(c != null){

     

                try{

     

                    list = (ListView) findViewById(R.id.showhistory_listview);

     

                }catch (Exception e) {

     

                    return;

     

                }

     

                

     

                mylist = new ArrayList<HashMap<String, String>>();

     

                

     

                while (c.moveToNext()){

     

                    HashMap<String, String> map = new HashMap<String, String>();  

     

                    map.put("historyCode", c.getString(0));   <-----取得第一個欄位的資料

     

                    map.put("historyProductName", c.getString(1));  

     

                    map.put("historyItemsCount", c.getString(2));            

     

                    mylist.add(map);      

     

                }

    2011-05-27