Score:0

JOptionPane.showMessageDialog does not work

in flag

I try to display a message dialog approving the success or otherwise of my Java program with the database. I used different ways to see if it is successfully connected or not. and yeah it the connection is successful but I do not get a message dialog approving it. I am using Eclipse on Mac. Here is my controller Class. Please help!

package application;

import java.net.URL; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ResourceBundle; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JOptionPane; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.control.Button; import javafx.scene.control.TextField;

public class SampleController implements Initializable {

 @FXML
    private Button btnLogin;

    @FXML
    private Button btnSignUp;

    @FXML
    private TextField txtGender;

    @FXML
    private TextField txtEmail;

    @FXML
    private TextField txtFullName;

    @FXML
    private TextField txtLoginEmail;

    @FXML
    private TextField txtLoginPassword;

    @FXML
    private TextField txtPassword;

    @FXML
    private TextField txtRePassword;

    private Connection conn = null;
    PreparedStatement pst = null;
    ResultSet rs = null;
    
    @FXML
    void fcnBtnLogin(ActionEvent event) 

        conn = dbConnection.connect();
        
        String sql = "Select * from tblSignUp where EMAIL=? AND PASSWORD=?";
        
        try {
            pst =conn.prepareStatement(sql);
            pst.setString(1, txtLoginEmail.getText());
            pst.setString(2, txtLoginPassword.getText());
            
            ResultSet rs = pst.executeQuery();
            if(rs.next() == true) {
                
                JOptionPane.showMessageDialog(null, "Login Successful!");
                
            }else {
                JOptionPane.showMessageDialog(null, "Login Unuccessful! Incorrect Username or Password");
            }
            
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    @FXML
    void fcnBtnSignUp(ActionEvent event) {
        
        conn = dbConnection.connect();
        
        String sql = "insert into tblSignUp (FULL_NAME, GENDER, EMAIL, PASSWORD, RE_PASSWORD) values (?,?,?,?,?)";
 
        
        try {
            pst= conn.prepareStatement(sql);
            
            pst.setString(1, txtFullName.getText());
            pst.setString(2, txtGender.getText());
            pst.setString(3, txtEmail.getText());
            pst.setString(4, txtPassword.getText());
            pst.setString(5, txtRePassword.getText());
            
            pst.execute();
            
            JOptionPane.showMessageDialog(null, "!");
            
        } catch (SQLException ex) {
            Logger.getLogger(SampleController.class.getName()) . log(Level.SEVERE, null,ex);

        }
    }

public void initialize(URL url, ResourceBundle rb) {
    
}

}

in flag
You may want to move this question to StackOverflow as it is *way* off topic for this forum ...
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.