gpt4 book ai didi

java - android 中的错误 - SQLite

转载 作者:行者123 更新时间:2023-11-29 03:40:29 24 4
gpt4 key购买 nike

我正在尝试查询我的数据库以返回输入到文本框中的名称。我已经能够查看数据库中的所有项目,但我想使用文本框搜索名称。当我输入姓名并点击搜索按钮时,log cat 显示错误“没有这样的列:john:编译时:SELECT name, gender, height, age, hair FROM details WHERE name= john ORDER by name.

 private void findRecords(){
EditText find = (EditText)findViewById(R.id.nameSearch);
EditText name = (EditText)findViewById(R.id.nameFound);
EditText gender = (EditText)findViewById(R.id.genderFound);
String s = find.getText().toString();
//Long l = Long.parseLong(s);
DatabaseClass hon = new DatabaseClass(this);

String returnedName = hon.getName(s);
String returnedGender = hon.getGender(s);

name.setText(returnedName);
gender.setText(returnedGender);

}


public String getName(String s) {
// TODO Auto-generated method stub
String[] columns = new String[] {NAME_COLUMN, GENDER_COLUMN, HEIGHT_COLUMN, AGE_COLUMN, HAIR_COLUMN};
Cursor c = sherlockdb.query(TABLE_NAME, columns, NAME_COLUMN +"="+ s, null, null, null, NAME_COLUMN);
if (c != null){
c.moveToFirst();
String name = c.getString(1);
return name;
}
return null;
}

请帮忙

最佳答案

替换:

Cursor c = sherlockdb.query(TABLE_NAME, columns, NAME_COLUMN +"="+ s, null, null, null, NAME_COLUMN);

与:

String[] args={s};
Cursor c = sherlockdb.query(TABLE_NAME, columns, NAME_COLUMN +"=?", args, null, null, NAME_COLUMN);

关于java - android 中的错误 - SQLite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13416869/

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