gpt4 book ai didi

java - 查询无法正常工作

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

我想进行查询并使用用户在编辑文本中输入的值,因为条件是 where 子句。在数据库helper.java类中:查询如下:

public Cursor patientHisto ( String value ) {
SQLiteDatabase db = this.getWritableDatabase();
Cursor res = db.rawQuery (" select dateap,diagnostic,prestreatment from patients_table, appointments_table, examinations_table where patients_table.id = appointments_table.idp and appointments_table.idap = examinations_table.id_ap and ID = ? order by name, familyname asc" , new String[] {value} );
return res;
}

在 ExaminatFragment.java 中:

public class ExaminatFragment extends Fragment {
DatabaseHelper myDB;
EditText id_p;
Button showhp;
String value;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState){
View v = inflater.inflate(R.layout.fragment_examinat, parent, false);
myDB = new DatabaseHelper(getActivity());

id_p = (EditText)v.findViewById(R.id.id_p_text);


getPatHisto( );
return v;
}

public void getPatHisto( ) {

value = id_p.getText().toString();

showhp.setOnClickListener(

new View.OnClickListener() {

@Override
public void onClick(View v) {
Cursor res = myDB.patientHisto(value);
if (res.getCount() == 0){

showMessage("Patient history", "No patient history found");
return;

}


StringBuffer buffer = new StringBuffer();
while (res.moveToNext()){
buffer.append("Dateap:"+res.getString(0)+"\n");
buffer.append("Diagnostic:"+res.getString(1)+"\n");
buffer.append("Prestreatment:"+res.getString(2)+"\n\n");




}
showMessage("Patient's history", buffer.toString());
}


}
);
}






public void showMessage(String title, String Message){

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setCancelable(true);
builder.setTitle(title);
builder.setMessage(Message);
builder.show();

}

运行应用程序时,在编辑文本中选择病人 ID 并单击按钮,它总是显示:未找到病人历史,即使病人有检查历史。请帮忙..提前谢谢您

最佳答案

在设置 Activity 时,您仅捕获 EditText 的内容一次。

value = id_p.getText().toString(); 移至点击监听器内,以在每次按下按钮时捕获当前内容。

关于java - 查询无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34632394/

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