在我的員工工資管理項目中,搜索文本字段不工作..i使用mysql工作臺和java .. 它沒有返回任何值.. 我該如何解決這個錯誤? 我的搜索文本字段如何工作????搜索文本字段沒有返回任何值
我的編碼是在這裏:
enter code here
private void txt_searchKeyReleased(java.awt.event.KeyEvent evt) {
try{
String sql ="select * from Staff_information where id=? ";
pst=conn.prepareStatement(sql);
pst.setString(1,txt_search.getText());
rs=pst.executeQuery();
String add1 =rs.getString("id");
txt_id.setText(add1);
String add2 =rs.getString("first_name");
txt_firstname.setText(add2);
String add3 =rs.getString("surname");
txt_surname.setText(add3);
String add4 =rs.getString("Dob");
txt_dob.setText(add4);
String add5 =rs.getString("Email");
txt_email.setText(add5);
String add6 =rs.getString("Telephone");
txt_tel.setText(add6);
String add7 =rs.getString("Address");
txt_address.setText(add7);
String add8 =rs.getString("Department");
txt_dep.setText(add8);
String add10 =rs.getString("Salary");
txt_salary.setText(add10);
String add11 =rs.getString("Address2");
txt_add2.setText(add11);
String add12 =rs.getString("Apartment");
txt_apt.setText(add12);
String add13 =rs.getString("Post_code");
txt_pc.setText(add13);
String add14 =rs.getString("Status");
txt_status.setText(add14);
String add15 =rs.getString("Date_hired");
txt_doj.setText(add15);
String add16 =rs.getString("job_title");
txt_job.setText(add16);
String add17 =rs.getString("Designation");
txt_design.setText(add17);
byte[] image = rs.getBytes("Image");
ImageIcon imageIcon = new ImageIcon(new ImageIcon(image).getImage().getScaledInstance(img.getWidth(), img.getHeight(), Image.SCALE_SMOOTH));
img.setIcon(imageIcon);
}catch(Exception e){
} finally {
try{
rs.close();
pst.close();
} catch(Exception e){
} }
我dnt理解你的答案。 –
我已經更新了我的答案 - 請參閱前兩段。希望能幫助到你。 – anacron
請參閱我的代碼片段中包含'rs.next()'的第7行。 – anacron