I want to display the information in a database table using multiple labels.
This information for each person is unique and pertains to each row in the table.
After logging in to the program, each person should be able to see their information and correct it if they want, by logging in to their profile page.
For each column of the table, I have provided a label, which displays the information of each person based on the column.
I wrote the following code to display the database data on the label, but when I run it, nothing is displayed!
I also do not know whether to use ResultSet and its methods or Statement and its methods to get the string to use in Label.
enter code here
private void displayProfileDetails(String resultSetQuery, Label label) {
DatabaseConnection connectToDrugDatabase = new DatabaseConnection();
try (
Connection connectionDB = connectToDrugDatabase.getConnection();
Statement statement = connectionDB.createStatement();
ResultSet resultSet = statement.executeQuery(resultSetQuery);) {
while (resultSet.next()) {
label Text
if (resultSet.next()) {
baseMessageLabel
Platform.runLater(() -> {
label.setText(resultSet.toString());
}
);
} else {
label.setText("null");
}
}
} catch (SQLException | ClassNotFoundException e) {
e.printStackTrace();
}
}
private void profileDetails() {
String firstNameDisplayQuery = "SELECT * FROM APP.users WHERE USERNAME = '" + userID + "'";
String lastNameDisplayQuery = "SELECT * FROM APP.users WHERE FIRSTNAME = '" + userID + "'";
String userNameDisplayQuery = "SELECT * FROM APP.users WHERE LASTNAME = '" + userID + "'";
String passwordDisplayQuery = "SELECT * FROM APP.users WHERE PASSWORD = '" + userID + "'";
String EmailDisplayQuery = "SELECT * FROM APP.users WHERE PHONENUMBER = '" + userID + "'";
String AddressDisplayQuery = "SELECT * FROM APP.users WHERE ADDRESS = '" + userID + "'";
String phoneNumberDisplayQuery = "SELECT * FROM APP.users WHERE JOB = '" + userID + "'";
String jobDisplayQuery = "SELECT * FROM APP.users WHERE EMAIL = '" + userID + "'";
displayProfileDetails(firstNameDisplayQuery, firstNameLabel);
displayProfileDetails(lastNameDisplayQuery, lastNameLabel);
displayProfileDetails(userNameDisplayQuery, userNameLabel);
displayProfileDetails(EmailDisplayQuery, emailLabel);
displayProfileDetails(AddressDisplayQuery, addressLabel);
displayProfileDetails(phoneNumberDisplayQuery, phoneNumberLabel);
displayProfileDetails(jobDisplayQuery, JobLabel);
displayProfileDetails(passwordDisplayQuery, passwordLabel);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…