有关解释,请参阅标题。
以下是我正在使用的方法:
public Cursor getClientByName(String name) throws SQLException {
name = name.trim();
Cursor mCursor =
mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID, KEY_NAME}, KEY_NAME + "=" + name, null,
null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
这是对方法的调用:
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long vId) {
String name = ((TextView) view).getText().toString();
// Toast.makeText(AvoidForeclosure.this, name, Toast.LENGTH_LONG).show();
Cursor cD = db.getClientByName(name);
cD.moveToLast();
int id = cD.getInt(0);
Intent intent = new Intent();
intent.setClass(view.getContext(), CurrentMarketValue.class);
intent.putExtra("clientId", id);
startActivity(intent);
}
});
我知道为什么它会抛出“No column found with name = Test”,虽然我的数据库浏览器显示确实有一个名为name的列和一行名为Test的列?
答案 0 :(得分:1)
public Cursor getClientByName(String name) throws SQLException {
name = name.trim();
String q = "SELECT _id, name FROM " + DATABASE_TABLE + " WHERE name=?";
Cursor mCursor = mDb.rawQuery(q, new String[] { name });
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
解决了这个问题。