0

I've just created a Java application with a JFrame as the main window that opens when I run the application.

I tried to build the project, but when double-clicking the jar file in the dist folder, I get an error that says "A Java exception has occured" with no further details.

What could the problem be?

Thanks

GUI form code:

    import java.sql.*;
    import java.util.logging.Level;
    import java.util.logging.Logger;

    public class Login extends javax.swing.JFrame {


    LoginClass lc;
    public Login() {
        this.lc = new LoginClass(this, UNField, PWField);        
       initComponents();
    }

    private void UNFieldActionPerformed(java.awt.event.ActionEvent evt) {                                        

    }                                       

    private void LoginBtnActionPerformed(java.awt.event.ActionEvent evt) {                                         
        try {
            lc.Login(UNField, PWField);
        } catch (SQLException ex) {
            Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
        }
    }                                        

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Login().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton LoginBtn;
    private javax.swing.JPasswordField PWField;
    private javax.swing.JLabel PWLabel;
    private javax.swing.JTextField UNField;
    private javax.swing.JLabel UNlabel;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration                   
}

LoginClass code:

    import java.sql.*;
    import javax.swing.*;


    public class LoginClass {
        Login l;
        JTextField un;
        JPasswordField pw;
        ResultSet rs;
        PreparedStatement pst;
        Connection conn = DBConn.ConnectDB();

    public LoginClass(Login log, JTextField u, JPasswordField p){
        l=log;
        un = u;
        pw = p;
    }    

    public void Login(JTextField u, JPasswordField p) throws SQLException{
        try{
        String name = u.getText();
        String password = "" + p.getText();
        String sql = "Select * from tblUsers where userName = '" + name + "' and password = '" + password + "'";
        pst = conn.prepareStatement(sql);
        rs = pst.executeQuery();
        if(rs.next()){
            JOptionPane.showMessageDialog(null, "Credentials are correct.");
            Menu main = new Menu();
            l.setVisible(false);
            main.setVisible(true);

        }
        else{
            JOptionPane.showMessageDialog(null, "Invalid credentials entered.");

        }
        } catch(SQLException e){
           JOptionPane.showMessageDialog(null, e);
        }
    }
}
Marko Vidalis
  • 331
  • 1
  • 7
  • 18

0 Answers0