help needed in java coding

can anyone help me in java coding
i am trying to building a frame which will ask 4 username and psw and if they mathches by looking in database ,it will automatically show new frame which shows account info of login user by rerieving info from another table

Replies

  • hbk
    hbk
    u talking abt JDBC??
  • elric
    elric
    You could be more specific, like in which part you need help? Database connectivity or GUI design?
  • jaichan
    jaichan
    Hi friend first of all u understand the database connectivity
  • Neha
    Neha
    hi!
    This is all related to database connectivity.
    You'll have to maintain a database for the same recording the logins and the passwords etc and connect it to your file.
  • niraj.kumar
    niraj.kumar
    You can follow this step
    1. You need to create a table to store this information
    2. Learn JDBC its easy ... make the connection.. u will find lots of tutorial on this .
    3. Make a simple UI is java swing ....

    thats it ... if u need further then reply ... i mean wat kind of problem u r facing ..... paste the error msg here ...(if u have any)
  • komputergeek
    komputergeek
    These are two classes from my project:


    Login.java :  
    
    import javax.swing.*; 
    import java.awt.event.*; 
    import java.sql.*; 
     
    public class Login 
    { 
        static JFrame f; 
        static JPanel p1; 
        static JPanel p2; 
        static JPanel p3; 
        static JLabel lUserName; 
        static JTextField tUserName; 
        static JLabel lPassword; 
        static JPasswordField pPassword; 
        static JButton bLogin; 
        static JButton bCancel;    
       
        public static void showLoginWindow () 
        {         
            f = new JFrame ("Login"); 
            p1 = new JPanel (); 
            p2 = new JPanel (); 
            p3 = new JPanel (); 
            lUserName = new JLabel ("User Name : "); 
            tUserName = new JTextField (20); 
            lPassword = new JLabel ("Password  :  "); 
            pPassword = new JPasswordField (20); 
            bLogin = new JButton ("Login"); 
            bLogin.setToolTipText ("Click here to Login"); 
            bLogin.setMnemonic('L'); 
            bLogin.addActionListener (new ActionListener () 
            { 
                public void actionPerformed (ActionEvent e) 
                {                                                  
                    try                     
                    {                                                                        
                        Connection con = null; 
                        Statement stmt; 
                        ResultSet rs;   
                           boolean flag=false;                                                                            
                        con = DBConnect.getCon ();                          
                        stmt = con.createStatement ();                                                                 
                        rs = stmt.executeQuery ("Select * from USERS  where USERNAME='" + tUserName.getText () + "' and PASSWORD = '" + pPassword.getText() + "'" ); 
                           while(rs.next()) 
                           {                                                 
                               if(rs.getString("USERNAME").equals(tUserName.getText()) &&   rs.getString("PASSWORD").equals(pPassword.getText())) 
                               {                                
                                   flag=true; 
                               }                                
                           }  
                           if(flag==false) 
                           {                                         
                               Result_AnalysisFrame frame= new Result_AnalysisFrame();  
                            frame.setVisible(true);   
                            f.hide(); 
                           } 
                           else 
                           { 
                               JOptionPane.showMessageDialog(null,"Login Failed !!!","Login Fail",JOptionPane.WARNING_MESSAGE); 
                           } 
                    } 
                    catch (Exception ex) 
                    { 
                        JOptionPane.showMessageDialog (null, ex, "Error", JOptionPane.INFORMATION_MESSAGE); 
                    } 
                } 
            } 
            ); 
            bCancel = new JButton ("Cancel"); 
            bCancel.setToolTipText ("Click here to Exit"); 
            bCancel.setMnemonic('C'); 
            bCancel.addActionListener (new ActionListener () 
            { 
                public void actionPerformed (ActionEvent e) 
                { 
                    System.exit (0); 
                } 
            } 
            ); 
            p1.add (lUserName); 
            p1.add (tUserName); 
            p2.add (lPassword); 
            p2.add (pPassword); 
            p3.add (bLogin); 
            p3.add (bCancel); 
     
            Box bx1 = Box.createVerticalBox (); 
            bx1.add (p1); 
            bx1.add (p2); 
            bx1.add (p3); 
     
            f.getContentPane ().add (bx1); 
            f.setVisible (true); 
            f.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); 
            f.setLocation (380, 280);       
            f.pack (); 
            f.setResizable (false);         
        } 
    } 
     
     
    
    DBConnect.java :
    
     
    import java.sql.*; 
    import oracle.jdbc.*; 
    import javax.swing.*; 
     
    public class DBConnect 
    { 
     
        public static Connection getCon () 
        { 
            Connection con = null; 
            String url = "jdbc:odbc:RA2"; 
     
            try 
            { 
                Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver"); 
                 
                con = DriverManager.getConnection (url, "RA", "RA"); 
            }                
            catch (Exception e) 
            { 
                JOptionPane.showMessageDialog (null, e, "Error", JOptionPane.INFORMATION_MESSAGE); 
            } 
            return con; 
        } 
    }
  • xero
    xero
    the info is not sufficient to rectify. Looking at code(the jdbc ones) it seems more like a driver issue. But before proceeding further, i think you should first go thru the basics of jdbc and the types of drivers available with databases.

    I'll just give you intro with the 4 types of drivers ->
    1. JDBC ODBC driver - this is the driver you have used in your program. This driver converts the jdbc calls into odbc acting as a bridge. So make sure have configured the odbc correctly. eg if you are using oracle as db so you have to configure the odbc for oracle. (for more reference, google 😁)

    2. Native-API partly Java technology-enabled driver - in this the java converts the jdbc calls into db api calls.

    3. Net-protocol fully Java technology-enabled driver - in this JDBC API calls is translated into a DBMS-independent net protocol which is then translated to a DBMS protocol by a server

    4. Native-protocol fully Java technology-enabled driver - converts JDBC technology calls into the network protocol used by DBMSs directly. This is a pure java based driver !

    The above was just informative, don't need to think deep into it. It won't harm to know.

    So the take-away is that your code is using the driver of type 1 so first you must check the configuration for Db specific odbc configuration.

You are reading an archived discussion.

Related Posts

I really want to know if there is a method of creating an mp3 player using a pen drive instead of a memory card. I have got three san disk...
Hi folks, Can anybody please tel me the exact use of clock signals? Thanks BS
Do we require Reservation in educational systems? If you ask me i will say a big NO..I personally feel that in the name of reservations we are trying to discriminate...
For those CEans who have pet cats, this will "rofl" you up! 😁 YouTube - An Engineer's Guide to Cats
Hi, I am a new CEan.I don't knw much about this site, so want all urs support to understand the site. By qualification i m an engineer in IT.Also i...