Trending This Week:

test

Post Top Ad

Your Ad Spot

Saturday, March 26, 2022

Simple Login Page Using MySql in JAVA



 package jdbc;

import java.sql.*; 

import java.util.Scanner;

public class JDBC {

    public static void main(String[] args) {

        try

        {  

            Class.forName("com.mysql.jdbc.Driver");  

            Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/mca","root","");  

            Statement stmt=con.createStatement();  

            

            Scanner sc =new Scanner(System.in);

            System.out.print("Enter Name For Login : ");

            String uname = sc.nextLine();

            System.out.print("Enter Name For Password : ");

            String upassword = sc.nextLine();

            

            ResultSet rs=stmt.executeQuery("select * from login where uname='"+uname+"'");  

            

            if(rs.next())

            {

             if(uname.equalsIgnoreCase(rs.getString(2)) && upassword.equals(rs.getString(3)))

             {

                System.out.println("Login Success Welcome  "+uname+","); 

             }

             else

             {

                 System.out.println("Username And Password Inrorrect Forgot Password");

             }

            }

            else

             {

                 System.out.println("Username And Password Inrorrect Forgot Password");

             }

            con.close(); 

          }

           catch(Exception e)

           {

               System.out.println(e);

           }  

    }     

}


If you have any query or problem with content or any improvement then please let me know in the comment section. I'm waiting for your comment. 



No comments:

Post a Comment

Post Top Ad

Your Ad Spot