When the user login, the login frame close and open another frame where I need the user login details to get the others details. My prepareStatement & resultSet are already set at the top. Still a newbie in java
login action listener
btnLogin.addActionListener(( ActionEvent ae) -> {
if (ae.getSource().equals(btnLogin)) {
DB_connection db_connection = new DB_connection();
String username = username_login_txtf.getText();
String password = password_login_txtf.getText();
try {
String sql = "SELECT * FROM user_profile as up WHERE up.username=? AND up.user_password=?";
preStatement = db_connection.connect().prepareStatement(sql);
preStatement.setString(1, username);
preStatement.setString(2, password);
res = preStatement.executeQuery();
boolean login = false;
while(res.next()) {
if(res.getString("username").equalsIgnoreCase(username) && res.getString("user_password").equalsIgnoreCase(password)) {
JOptionPane.showMessageDialog(loginPanel, "You have Logged in!");
login = true;
fr.dispose();
Main_menu.main(null);
break;
} ...
My other frame where i need to retrieve that specific user login data
btnSearch.addActionListener(( ActionEvent ae) -> {
if (ae.getSource().equals(btnSearch)) {
// Right now i am getting the username value from another text field that I have set in this form but I want to retrieve that value directly form the login frame
String get_username = username_profile_txtf.getText();
DB_connection db_connection = new DB_connection();
try{
preStatement = db_connection.connect().prepareStatement("Select * from user_profile where username = ?");
// here I need the user login username from the login form
preStatement.setString(1, get_username);
res = preStatement.executeQuery();
if (res.next()){
String username = res.getString("username");
username_profile_txtf.setText(username);
...
}
preStatement.close();
res.close();
} catch(SQLException ex){
System.out.println(ex.getMessage());
} finally {
db_connection.disconnect();
}
}
});