2011-07-29 13 views
1

私の要件は、オブジェクトを送信する必要があるいくつかのパラメータのクエリを渡すときです。リストしない。Android Sqliteクエリ

私は、コードを書かれている:

public RDExecutive getExecutiveObject(String executivename){ 
    DBAdapter dbAdapter = DBAdapter.getDBAdapterInstance(this); 
    dbAdapter.openDataBase(); 
    System.out.println(" ---- executivename --- " + executivename); 
    String query="SELECT * FROM RDExecutive WHERE ExecutiveName = ?';"; 
    String[]d = new String[]{executivename}; 
    ArrayList stringList = dbAdapter.selectRecordsFromDBList(query, d); 

    dbAdapter.close(); 

    ArrayList<Object> rdExecutiveObject = new ArrayList<Object>(); 
    RDExecutive rdExecutive = new RDExecutive(); 
    System.out.println(" -- stringList.size() -- " + stringList.size()); 

    for (int i = 0; i < stringList.size(); i++) { 
     ArrayList<Object> arrayList2 = (ArrayList<Object>) stringList.get(i); 
     ArrayList<Object> arrayList = arrayList2; 
     ArrayList<Object> list = arrayList; 

     try { 
      rdExecutive.setBusinessUnit((String) list.get(0)); 
      rdExecutive.setExecutiveCode((String) list.get(1)); 
      rdExecutive.setExecutiveName((String) list.get(2)); 
      rdExecutive.setTerritoryCode((String) list.get(10)); 

     } catch (Exception e) { 
      Log.i("***" + SalesRouteActivity.class.toString(), e.getMessage()); 
     } 
     rdExecutiveObject.add(rdExecutive); 
    } 
    return rdExecutive; 
} 

このメソッドはRDExecutiveオブジェクトを返します。私はこの部分を実行すると、私たちは照会するパラメータを渡したいんどのようにエラーに

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xont.controller/com.xont.controller.DownlaodTableActivity}: 

android.database.sqlite.SQLiteException: unrecognized token: "';": , while compiling: 
SELECT * FROM RDExecutive WHERE ExecutiveName = ?'; 

ました。

答えて

1

あなたはsemicolongは必要ありません( ";")

String query="SELECT * FROM RDExecutive WHERE ExecutiveName = ?'"; 

あなたはSQLの構文エラーを持っている

+0

ありがとうございました。 – Piraba

0

問題ないはずです。一重引用符を削除する必要があります。つまり、

// This line has the error: 
String query="SELECT * FROM RDExecutive WHERE ExecutiveName = ?';"; 

// This is the same line with the error fixed: 
String query="SELECT * FROM RDExecutive WHERE ExecutiveName = ?;";