我正在尝试使用 JavaFX 创建一个应用程序。我想在成功登录后获取当前登录的用户 ID 和用户名。我想将其显示在主页中。我怎样才能做到这一点?请帮忙
MediaController.java
@FXML
private Label tf_getname;
@FXML
void happyButton(ActionEvent event) {
DbConnect dbconnect=new DbConnect();
Connection conn=dbconnect.getConnection();
String username = tf_getname.getText();
// String source1 = event.getSource().toString(); //yields complete string
//String source2 = event.getPickResult().getIntersectedNode().getId(); //returns JUST the id of the object that was clicked
// System.out.println("Full String: " + source1);
// System.out.println("Just the id: " + source2);
// System.out.println(" " + source2);
try {
String sql = "SELECT name FROM users WHERE name='"+username+"'";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()){
tf_getname.setText(rs.getString("name"));
}
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
慕码人2483693
缥缈止盈
相关分类