954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Java MySql Login Form...

I'm having a hell of a time trying to make a login form.

This is what I have at the moment....

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

class LoginDemo extends JFrame{
 JButton SUBMIT;
 JLabel label1,label2;
 final JTextField  text1,text2;
  LoginDemo(){
    setTitle("Login Form");
    setLayout(null);
    label1 = new JLabel();
    label1.setText("Username:");
    text1 = new JTextField(15);

    label2 = new JLabel();
    label2.setText("Password:");
    text2 = new JPasswordField(15);

    SUBMIT=new JButton("SUBMIT");
    label1.setBounds(100,100,100,20);
    text1.setBounds(200,100,200,20);
    label2.setBounds(100,130,100,20);
    text2.setBounds(200,130,200,20);
    SUBMIT.setBounds(200,160,100,20);
   add(label1);
   add(text1);
   add(label2);
   add(text2);
   add(SUBMIT);

   setVisible(true);
   setSize(500,300);

 SUBMIT.addActionListener(new ActionListener(){
   public void actionPerformed(ActionEvent e){
	
    String value1=text1.getText();
    String value2=text2.getText();
    try{
    	Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from userInfo where username='"+value1+"' and password='"+value2+"'");
           int count=0;
           while(rs.next()){
               count++;
           }
          if(value1.equals("") && value2.equals("")) {
          JOptionPane.showMessageDialog(null,"Enter login name or password","Error",JOptionPane.ERROR_MESSAGE);
          }
          else if(count>0){
          System.out.println("Login Successful");
          page.setVisible(true);
          }
          else{
          text1.setText("");
          text2.setText("");
          System.out.println("Invalid Login name or password");
          }
    }
    catch(Exception e1){}
}
 });
  }
  public static void main(String arg[]){
  new LoginDemo();
}
}


When I hit my submit button, absolutely nothing happens...
Help?

Thanks

oldezwe
Light Poster
36 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

How do i find my driver information?

oldezwe
Light Poster
36 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

The following line (line 63) is an absolute no-no when debugging

catch(Exception e1){}

if any problem of any kind happens in the preceding 22 lines you have just told Java to carry on as if nothing happened, and don't tell you anything.
Replace it with

catch(Exception e1){ e1.printStackTrace();}

and you'll probably get an error message that tells you exactly what went wrong.

JamesCherrill
Posting Genius
Moderator
6,371 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

This is the error.

What does this mean? and how do i fix it?

oldezwe
Light Poster
36 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

Google java.lang.ClassNotFoundException: com.mysql.jdbc.Driver and you'll get lots of relevant answers

JamesCherrill
Posting Genius
Moderator
6,371 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: