我在FXML文件中创建了一个Tableview并填充了TableView。我还创建了另一个FXML文件StaffDetails,当我点击tableview上的一行时,StaffDetails FXML文件标签将插入该行的内容。我的问题是,对于每一行,我点击StaffDetails FXML文件只插入第1行的内容,而不是我点击的行的内容..请在下面是代码。
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"));