I have created a Tableview in FXML file and populated the TableView. I have also create another FXML file StaffDetails that when I click on a row on the tableview the StaffDetails FXML fileLabels are inserted with that row's content. my problem is that for every row I click on the StaffDetails FXML file is insert with the content of row 1 only and not the content of the row I click on.. Please below is the code.
viewEmployee.setOnMouseClicked(e->{
try {
Employee user =(Employee)viewEmployee.getSelectionModel().getSelectedItem();
String details="select *from Employee where STAFFID =?";
pstmt=conn.prepareStatement(details);
pstmt.setString(1,user.getStaffId());
rs=pstmt.executeQuery();
Stage stage = new Stage();
Parent root = FXMLLoader.load(getClass().getResource("StaffDetails.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
@Override
public void initialize(URL location, ResourceBundle resources) {
try {
Class.forName("org.apache.derby.jdbc.ClientDriver");
conn=DriverManager.getConnection("jdbc:derby://localhost:1527/Employee","Conduct","ccb");
String details="select *from Employee";
pstmt=conn.prepareStatement(details);
rs=pstmt.executeQuery();
rs.next();
st.setText(rs.getString("staffId"));
su.setText(rs.getString("surname"));
fn.setText(rs.getString("firstName"));
on.setText(rs.getString("otherNames"));
db.setText(rs.getString("dateOfBirth"));
sx.setText(rs.getString("sex"));
Aucun commentaire:
Enregistrer un commentaire