我有一个 jTextField 和一个 jLabel。我想在用户完成输入后自动将数据从数据库获取到我的标签。
subcode_txt.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
Object obj=e.getSource();
if(obj==subcode_txt){
jst=subcode_txt.getText();
try{
rs=st.executeQuery("Select * from facultydtls where sub_code like '"+jst+"'");
rs.next();
faculty_lab.setText(rs.getString("f_name"));
sem_lab.setText(rs.getString("sem"));
subject_lab.setText(rs.getString("sub"));
department_lab.setText(rs.getString("dept"));
rs.close();
}
catch(Exception ewt){
JOptionPane.showMessageDialog(null,"Invalid Subject Code");
}
}
}
});