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(); } }