Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Login form using JSP and MySQL

In this session you will learn how to develop a Login form using jsp and MySQL database connection.MySQL has always been my favorite database because it’s very easy to use.You can use any IDE like Netbeans or Eclipse to build a JSP application. I prefer Netbeans over Eclipse.e building the application, make sure you have the MySQL Java Connector added to the libraries. Without it, the server (for e.g. Glass Fish Server) will throw an error.

Step 1: Create Login page

        Login Demo with JSP







Step 2: Now create the validation page

After creating login page,this page will validate the username and password against the MySQL database.

        String username = request.getParameter("username");  
        String password = request.getParameter("password");
        Class.forName("com.mysql.jdbc.Driver");  // MySQL database connection
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/javademo?" + "user=root&password=");   
        PreparedStatement pst = conn.prepareStatement("Select user,pass from login where user=? and pass=?");
        pst.setString(1, username);
        pst.setString(2, password);
        ResultSet rs = pst.executeQuery();                       
           out.println("Valid login credentials");       
           out.println("Invalid login credentials");           
   catch(Exception e){      
       out.println("Something went wrong !! Please try again");      

Once you have finished both your login and validate page, you can run the application in the browser. 


You must add JAR files when you use MySql database. In this case make sure you have added the MySQL Java Connector JAR file.

This post first appeared on Learnprogramingbyluckysir, please read the originial post: here

Share the post

Login form using JSP and MySQL


Subscribe to Learnprogramingbyluckysir

Get updates delivered right to your inbox!

Thank you for your subscription