簡體   English   中英

登錄對話框不顯示歡迎

[英]Login dialog doesn't display welcome

當我輸入用戶名和密碼,然后單擊登錄按鈕時, welcome.java不會打開,它僅將輸出顯示為消息對話框。 它不會打開welcome.java 編碼沒有錯誤; 既不編碼也不連接。 登錄后, welcome.java應該會打開,但根本不會打開。 請幫忙

String path = "jdbc:mysql://localhost/";
String place = "hotel";

try {
    Class.forName("com.mysql.jdbc.Driver");
    Connection myconnection = DriverManager.getConnection(path + place, "root", "");
    try {
        String a = "select usertype from usertable where username=? and password=? ";
        PreparedStatement mystatement = myconnection.prepareStatement(a);
        mystatement.setString(1, username.getText());
        mystatement.setString(2, password.getText());       
        ResultSet myresult;
        myresult = mystatement.executeQuery();
        if (myresult.next()) {
            if (myresult.getString("usertype").equals("ADMIN")) {

                JOptionPane.showMessageDialog(rootPane, "Admin");
                parent1 obj = new parent1();
                obj.setVisible(true);

            } else if (myresult.getString("usertype").equals("CLIENT")) {

                JOptionPane.showMessageDialog(rootPane, "Client");
                welcome2 obj = new welcome2();
                obj.setVisible(true);
            } else {
                JOptionPane.showMessageDialog(rootPane, myresult.getString("usertype"));

            }
            //this.setVisible(false);
        } else {
            JOptionPane.showMessageDialog(rootPane, "Wrong Username/Password");
        }
        mystatement.close();
        myconnection.close();
    } catch (Exception e) {
        JOptionPane.showMessageDialog(rootPane, "Error in Query" + e.getMessage());
    }
} catch (Exception e) {
    JOptionPane.showMessageDialog(rootPane, "Error in Connection" + e.getMessage());
}
}

試試這個代碼; 雖然問題尚不清楚..希望該代碼有幫助..

    try{
            if(!myresult.next()){
           //no logins found,login failes
           JOptionPane.showMessageDialog(null, "Invalid Login Details... Try Again","ALERT!",JOptionPane.ERROR_MESSAGE);  
        }else{
           //found record,login succeeded
             if (myresult.getString("usertype").equals("ADMIN")) {
                    JOptionPane.showMessageDialog(rootPane, "Admin");

                    parent1 obj = new parent1();
                    obj.setVisible(true);
                    this.dispose();
             } else if (myresult.getString("usertype").equals("CLIENT")) {

                    JOptionPane.showMessageDialog(rootPane, "Client");

                    welcome2 obj = new welcome2();
                    obj.setVisible(true);
                    this.dispose();
             }
       }

           }catch(SQLException | HeadlessException e){
                JOptionPane.showMessageDialog(null, "wrong "+e);
           }finally{
                try{
                   pst.close();
                }catch(Exception e){
                   JOptionPane.showMessageDialog(null, "errorr "+e);
                }
           }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM