2014-01-08 311 views
0

如何解決該錯誤如何獲取數組列表查詢的結果集在Cursor對象中返回。還有,你將使用遊標使用一些常用的方法將內容添加到數據庫中

public class DBAdapter { 
     Context c; 
     CluecatalogOpenHelper helper; 
     SQLiteDatabase db; 
     int flag=0; 

     public DBAdapter(Context ctx) { 
      super(); 
      this.c = ctx; 
      helper=new CluecatalogOpenHelper(ctx); 
     } 
     public void openDB(){ 

      db=helper.getWritableDatabase(); 
     } 
     public void closeDB(){ 
      db.close(); 
     } 

     public void addRow(String name, byte[] data1) { 

       openDB(); 
       ContentValues values = new ContentValues(); 
       values.put("name", name); 
       values.put("object",data1); 
       db.insert("topsearch", null, values); 
       closeDB();   
     } 


     public void deleteRow(String name) 
     { 
     try { 
db.execSQL("delete from topsearch where name = (?)",new String[]{""+name}); 
     } catch (SQLException e) { 
     e.printStackTrace(); 
           } 
     } 

     public Cursor showData(){ 
     try{ 
     Cursor c = db.query("topsearch", new String[]{"name","object"}, null, null,null, null,null); 
      return c; 
      }catch(Exception e) { 
      e.printStackTrace(); 
      return null; 
      }}} 

如何解決這個錯誤

+0

請把這個問題翻譯成英文! –

+1

有點難以理解:/ – GhostDerfel

+1

你試圖克服的錯誤是什麼? – BRFennPocock

回答

0

我不知道你問什麼,但如果你問你怎麼拉出來結果出來的光標對象,並進入列表你會這樣做:

List list = new ArrayList(); 
Cursor c = db.query("topsearch", new String[]{"name","object"}, null, null,null, null,null); 

while(c.moveToNext()) 
{ 
    //populate your return object from the cursor here 
    //i'm just making this part up 
    Obj obj = new Obj(); 

    obj.setName(c.getString(0)); //0 being the column index 

    list.add(obj); 
} 

return list;