Piraba
Piraba

Reputation: 7004

Android Sqlite query

My requirement is when I pass some paramenter query need to send object. not list.

I have written the code :

 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;
}

This method is return RDExecutive object.

When I run this part , I got error

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 = ?';

How do we want to pass parameter to query.

Upvotes: 1

Views: 452

Answers (2)

Stephen Quan
Stephen Quan

Reputation: 26309

You have a SQL syntax error. You need to remove a single quote, i.e.

 // 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 = ?;";

Upvotes: 0

Sathyajith Bhat
Sathyajith Bhat

Reputation: 21851

You don't need the semicolong (";")

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

Should be fine

Upvotes: 1

Related Questions