JavaFX 8 Tutorial 43 - Fetch Database Values on Table KeyReleased Method
The code written in the tutorial is :
table.setOnKeyReleased(e ->{
if(e.getCode()== KeyCode.UP || e.getCode() == KeyCode.DOWN){
try {
User user = (User)table.getSelectionModel().getSelectedItem();
String query = "select * from UserDatabase where ID = ?";
pst = conn.prepareStatement(query);
pst.setString(1, user.getID());
rs = pst.executeQuery();
while(rs.next()){
id.setText(rs.getString("ID"));
fn.setText(rs.getString("FirstName"));
ln.setText(rs.getString("LastName"));
em.setText(rs.getString("Email"));
mobile.setText(rs.getString("MobileNo"));
un.setText(rs.getString("Username"));
pw.setText(rs.getString("Password"));
((TextField)date.getEditor()).setText(rs.getString("DOB"));
if(null != rs.getString("Gender"))switch (rs.getString("Gender")) {
case "Male":
male.setSelected(true);
break;
case "Female":
female.setSelected(true);
break;
default:
male.setSelected(false);
female.setSelected(false);
break;
}else{
male.setSelected(false);
female.setSelected(false);
}
}
pst.close();
rs.close();
} catch (SQLException ex) {
Logger.getLogger(Tutorial14.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
Comments
Post a Comment