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
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=?");
ResultSet rs = pst.executeQuery();
out.println("Valid login credentials");
out.println("Invalid login credentials");
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.