我试图从sqlite table中获取我的android代码中的一些数据。我收到一个无法识别的令牌异常。请帮助。 这是我的代码的相关部分:
private static final String APPS_CREATE =
"create table applist (" +
"_id integer primary key, " +
"deviceid int(10) not null," +
"catid int(10)," +
............
private static final String APPCNT_CREATE =
"create table appcntlist (" +
"_id integer primary key, "+
"appcntid int , " +
"cntappid int);";
.........................
public Cursor fetchCntNotes(String cnt){
Cursor appfinlist=null;
Cursor temp=mDb.query(CNT_TABLE, new String[]{KEY_ROWID}, KEY_CNTNM + "=\"" + cnt + "\"", null, null , null, null);
Cursor applist;
if(temp.moveToFirst()){
id=temp.getInt(temp.getColumnIndexOrThrow(DbAdapter.KEY_ROWID));
Log.d("amit","countryname id: "+ id);
applist=mDb.rawQuery("SELECT appcntid FROM appcntlist WHERE cntappid = "+id, null);
if(applist.moveToFirst()){
int[] cntin=new int[applist.getCount()];
for(int i=0;i<applist.getCount();i++){
Log.d("amit","countryname id appid: " + applist.getInt(applist.getColumnIndexOrThrow(DbAdapter.KEY_APPCNTID)));
cntin[i]=applist.getInt(applist.getColumnIndexOrThrow(DbAdapter.KEY_APPCNTID));
Log.d("amit","countryname id cnt var: " + cntin[i]);
applist.moveToNext();
}
appfinlist = mDb.rawQuery("SELECT * FROM applist WHERE _id IN "+cntin+")", null);
return appfinlist;
}
这是logcat的相关部分
E / AndroidRuntime(6447):引起:android.database.sqlite.SQLiteException:无法识别的令牌:“[I @ 406488d0]”:,同时编译:SELECT * FROM applist WHERE _id IN [I @ 406488d0]答案 0 :(得分:0)
删除cntin
并重试我认为查询无效,查询字符串末尾附加了变量。
答案 1 :(得分:0)
我使用了此链接中提出的方法。查看接受答案给出的解决方案 IN clause and placeholders