{ads}

6/recent/ticker-posts

Login page in java net beans IDE



Tools Required :
  • Net Beans IDE
  • My Sql WorkBench
  • My Sql Connector
Library imports:
  • import java.sql.Connection;
  • import java.sql.DriverManager;
  • import java.sql.PreparedStatement;
  • import java.sql.ResultSet;
  • import javax.swing.JOptionPane;
Login Credential verification code :

 void userverification(String username , String password){
	 try {
         Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/fees","root", "root");
          String sql = "Select * from signupdata where user_name=? and password=?";
         PreparedStatement pst = connection.prepareStatement(sql);
         pst.setString(1, username);
         pst.setString(2, password);
         ResultSet rs = pst.executeQuery();
         if (rs.next()) {
         
             HomePage ah = new HomePage();
             ah.setVisible(true);
             this.dispose();
            
             JOptionPane.showMessageDialog(this, "You have successfully logged in");
         } else {
             JOptionPane.showMessageDialog(this, "Wrong Username & Password");
         }
     } catch (Exception exception) {
         exception.printStackTrace();
     }

User verification function take two strings one is user name and other is password. After getting these  to field we can match on our database .If user name or password can found then we are able to interact with system.

Mouse Clicked Event code

String username,password;
username = txt_username.getText();
password = txt_password.getText();
if(username.trim().equals("")||password.trim().equals("")){
  JOptionPane.showMessageDialog(null,"Please Enter username and Password");
}
else{
      userverification(username,password);
}

Post a Comment

0 Comments