gpt4 book ai didi

Android Sqlite 查询

转载 作者:行者123 更新时间:2023-11-30 04:35:52 25 4
gpt4 key购买 nike

我的要求是当我传递一些参数查询时需要发送对象。不列出。

我写了代码:

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

我们要如何将参数传递给查询。

最佳答案

你不需要分号 (";")

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

应该没问题

关于Android Sqlite 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6868800/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com