Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By Norm

Thread: My code display nothing after pressing Login in user verification in Java (gui)?

  1. #1
    ahmed666916 is offline Member
    Join Date
    Dec 2013
    Posts
    2
    Rep Power
    0

    Default My code display nothing after pressing Login in user verification in Java (gui)?

    XML Code:
     Here right below is my code for Login user interface. I am trying to create a user verification. I have done     everything I was supposed to do but my code don't display anything after pressing Login button in the console ? Kindly please help and see my code below .What's wrong with this code.
    
    
    package login;
    
    /**
     *
     * @author Ahmed Adnan
     */
    import javax.swing.*;                              // For Frame
    import java.awt.event.*;                           // For action Listener
    import java.sql.*;                                // For Database
    
    public class Login {
        /*    Three instance varaibles     */
        Connection con;
        Statement st;
        ResultSet rs;
        
        JFrame f = new JFrame("User Login");
        JLabel l = new JLabel("Username:");
        JLabel l1 = new JLabel("Password:");
        JTextField t = new JTextField(10);
        JTextField t1 = new JTextField(10);
        JButton b = new JButton("Login");
        
        
        /*     CONSTRUCTOR                 */
        public Login()
        {
            /*    METHODS                */
            connect();
            frame();
            
            
            
            
        }
        
        public void connect()
        {
            try
            {
                
                /*         DECLARING DRIVER                             */
                String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
                Class.forName(driver);
                
                String db = "jdbc:odbc:Database1";
                /*  THIS WILL GET A CONNECTION TO OUR DATABASE  */
                con = DriverManager.getConnection(db);
                st = con.createStatement();
                
                
                
                
            }
            catch(Exception ex)
            {
                
            
        }
        }
        
        public void frame()
        {
            f.setSize(600, 400);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setVisible(true);
            
            JPanel p = new JPanel();
            p.add(l);
            p.add(t);
            p.add(l1);
            p.add(t1);
            p.add(b);
            
            f.add(p);
            
            b.addActionListener(new ActionListener(){
              public void actionPerformed(ActionEvent e)
              {
                  
                  try{
                  String user = t.getText().trim();
                  String pass = t1.getText().trim();
                  
                  String sql = "select user,pass from Table2 where user='"+user+"'and pass='"+pass+"'";
                  rs = st.executeQuery(sql);
                  
                  int count = 0;
                  while(rs.next())
                  {
                      count = count + 1;
                  }
                  
                  if(count == 1)
                  {
                      JOptionPane.showMessageDialog(null, "User found, Access granted! ");
                  }
                  
                  else if(count > 1)
                  {
                      JOptionPane.showMessageDialog(null, "Duplicate user, Access denied! ");
                  }
                  
                  else
                  {
                      JOptionPane.showMessageDialog(null, "User not found! ");
                  }
                  }
                  catch(Exception ex){
                      
                  }
              }  
            });
            
        }
        
        
        
        public static void main(String[] args) {
            
            new Login();
            
                
                
            }
        }
    Last edited by ahmed666916; 12-24-2013 at 11:31 AM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,423
    Rep Power
    25

    Default Re: My code display nothing after pressing Login in user verification in Java (gui)?

    One problem I see is that the catch blocks are empty so you do NOT see messages for any errors that happen.
    Add a call to the printStackTrace() method to all the catch blocks so you will see a message if there is an error.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    ahmed666916 is offline Member
    Join Date
    Dec 2013
    Posts
    2
    Rep Power
    0

    Default Re: My code display nothing after pressing Login in user verification in Java (gui)?

    Quote Originally Posted by Norm View Post
    One problem I see is that the catch blocks are empty so you do NOT see messages for any errors that happen.
    Add a call to the printStackTrace() method to all the catch blocks so you will see a message if there is an error.


    After putting ex.printStackTrace(); in th catch blocks I get the following errors!
    java.sql.SQLException: [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6964)
    at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7121)
    at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3080)
    at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323)
    at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDrive r.java:174)
    at java.sql.DriverManager.getConnection(DriverManager .java:571)
    at java.sql.DriverManager.getConnection(DriverManager .java:233)
    at login.Login.connect(Login.java:51)
    at login.Login.<init>(Login.java:31)
    at login.Login.main(Login.java:131)
    java.lang.NullPointerException

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,423
    Rep Power
    25

    Default Re: My code display nothing after pressing Login in user verification in Java (gui)?

    The specified DSN contains an architecture mismatch between the Driver and Application
    That sounds like a DB configuration problem. I don't know anything about that so you will need to do some research on how to fix it.
    ahmed666916 likes this.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Login in java show all user and all usertype
    By Fuhans in forum New To Java
    Replies: 1
    Last Post: 11-18-2013, 12:35 PM
  2. Login in java show all user and all usertype
    By Fuhans in forum Advanced Java
    Replies: 1
    Last Post: 11-18-2013, 12:17 PM
  3. Replies: 0
    Last Post: 09-15-2013, 05:24 PM
  4. Java with MS Access Database User login
    By pateldpk in forum JDBC
    Replies: 2
    Last Post: 04-20-2012, 03:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •