Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: run time error

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    4
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default run time error

    hello,

    i need help with the following code..i was trying to link java and MS access dataBase to create a user login dialog box wherein after entering the data into the text field and pressing login button i should get the desire output.though the following code is error free but still when i try to run it i am not getting the desired output i.e the login button is not responding ..when i click the login button i am getting no response.


    kindly help me with the following code

    import javax.swing.*;
    import java.awt.event.*;
    import java.sql.*;
     
    public class Login{
    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(35);
    JTextField t1=new JTextField(35);
    JButton b=new JButton("Login");
    public Login()
    {
    connect();
    frame();
    }
    public void connect()
    {
    try
    {
    String driver="sun.jdbc.odbc.JdbcOdbcDriver";
    Class.forName(driver);
    String db="jdbc:odbc:nayeemohamed";
    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 shoeb 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 nayeemohamed; August 6th, 2012 at 11:45 AM.


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: run time error

    Please edit your post and place [code=java] before your code, and [/code]after your code.

  3. #3
    Junior Member
    Join Date
    Aug 2012
    Posts
    4
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: run time error

    in the above program i have created a database nayeemohamed using MS Access 2007 and entered 3 values for user and pass in the table named shoeb..
    though i am not getting any compilation error i m not getting the desired output..can any body figure out why??

  4. #4
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: run time error

    What exactly is happening? Does the button click and nothing happens, does the button click and stay in it's "clicked" state, or are you just not getting the output message that you expect? If its the last one, what do you expect to get and what are you getting?

    Also, are you aware you have spaces around your password variable in the database call?
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Similar Threads

  1. Run Time Error
    By Tanmaysinha in forum What's Wrong With My Code?
    Replies: 22
    Last Post: March 8th, 2012, 11:29 AM
  2. I am having a hard time fixing this error
    By KuruptingYou in forum What's Wrong With My Code?
    Replies: 7
    Last Post: August 28th, 2011, 10:12 PM
  3. Help with run time error
    By white97 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: August 11th, 2011, 12:35 PM
  4. Run Time Error.
    By seymour001 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: August 10th, 2011, 12:10 PM
  5. [SOLVED] Run time error
    By moodycrab3 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 7th, 2011, 11:05 AM