The Login Page In Java is a desktop application that is used to submit login credentials to access a restricted page. The username and password are the only fields on a login form.
Further, each user should have their own username, which can be an email address, a phone number, or anything else.
Importance Of Code For Login Page
Every computer user should have their own user account so that only they have access to their files and programs. To protect users’ privacy, each user account should only be accessible by entering a username and password.
Project Details and Technology
Project Name: | Log In Page Project In Java With Source Code |
Abstract | Log In Page in Java is the process by which an individual gains access to a computer system by identifying and authenticating themselves. |
Language/s Used: | JAVA |
JAVA version (Recommended): | 8 |
Database: | MySQL |
Type: | Desktop Application |
Developer: | Source Code Hero |
Updates: | 0 |
About Login Page Project
This Login Page Code In Java was created with the help of JAVA, MySQL Connector, and MySQL Database. This Login Code In Java is a simple project that uses the Java programming language to connect to a MySQL database.
A graphical user interface was used to make a login in Java (GUI). This Login Form Java Swing is suitable for beginners who wish to learn java programming language since it is extremely simple and easy to grasp by the user.
How Should I Use For GUI In Java?
Since then, Swing has been the most popular Java graphical user interface technology.
The Abstract Window Toolkit (AWT) is a set of APIs for creating a graphical user interface for Java programs. Swing eventually took its place.
Swing is a set of APIs that contain GUI components that may be used to create applications.
How To Create a Login Page In Java
Here are explanations on how to create a login page in Java.
Declaring and Naming Variables
You can change the variables of the given TextFields and buttons below.
For the Textfield:
- jTextField1 = uname
- jTextField2 = upass
For the Button:
- jButton1 = login_button
The code given below is the MySQL connection
In this module is the connection under Java into the mysql database.
try {
Class.forName("com.mysql.jdbc.Driver");
String conURL = "jdbc:mysql://localhost/user?" +
"user=root&password=";
java.sql.Connection con = DriverManager.getConnection(conURL);
} catch (SQLException x) {
x.printStackTrace();
} catch (ClassNotFoundException ex) {
Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
}
The Code Given Below Check The Input User If Account Exist or Not
This line of code explains that check the user input in the username and password field if exist or not.
//String query = "SELECT * FROM `the_app_users` WHERE `u_uname` =? AND `u_pass` =?";
java.sql.Statement stmt = con.createStatement();
String sql = "SELECT * FROM `tbluser` WHERE `u_uname` = '" + uname1 + "' AND `u_pass` ='" + pass1 + "'";
stmt.execute(sql);
ResultSet rs = stmt.executeQuery(sql);
// java.sql.Statement stmt = con.createStatement();
// rs = ps.executeQuery();
if (rs.next())
{
//successful else
JOptionPane.showMessageDialog(null, "Login Successfull", "Login Success", 1);
//home mf = new home();
new home().setVisible(true);
this.dispose();
} else {
// error message
JOptionPane.showMessageDialog(null, "Incorrect Username Or Password", "Login Failed", 2);
}
Complete Source Code
Put this complete source code under the “login_button” button.
try {
Class.forName("com.mysql.jdbc.Driver");
String conURL = "jdbc:mysql://localhost/user?"
+
"user=root&password=";
java.sql.Connection con = DriverManager.getConnection(conURL);
//MyConnection();
// PreparedStatement ps;
//ResultSet rs;
//string username or string user
String uname1 = uname.getText();
// password label and password string
String pass1 = String.valueOf(upass.getText());
//String query = "SELECT * FROM `the_app_users` WHERE `u_uname` =? AND `u_pass` =?";
java.sql.Statement stmt = con.createStatement();
String sql = "SELECT * FROM `tbluser` WHERE `u_uname` = '" + uname1 + "' AND `u_pass` ='" + pass1 + "'";
stmt.execute(sql);
ResultSet rs = stmt.executeQuery(sql);
// java.sql.Statement stmt = con.createStatement();
// rs = ps.executeQuery();
if (rs.next())
{
//successful else
JOptionPane.showMessageDialog(null, "Login Successfull", "Login Success", 1);
//home mf = new home();
new home().setVisible(true);
this.dispose();
} else {
// error message
JOptionPane.showMessageDialog(null, "Incorrect Username Or Password", "Login Failed", 2);
}
} catch (SQLException x) {
x.printStackTrace();
} catch (ClassNotFoundException ex) {
Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
}
Output:
Login Success
Opening New Window
To start executing a Login System in Java, make sure that you have NetBeans IDE or any platform of Java installed on your computer.
Steps On How To Run The Login Page Code In Java With Source Code
Time needed: 5 minutes
These are the steps on how to run a Login Page In Java With Source Code.
- Step 1: Download the source code.
First, download the source code given below.
- Step 2: Extract file.
Next, after you finished download the source code, extract the zip file.
- Step 3: Click open project.
Next, open netbeans IDE and click open project and choose your download source code.
- Step 4: Run the project.
Next, right-click the project folder and click run.
Downloadable Source Code Here!
Summary
The Login Page Code In Java was created with the help of JAVA, MySQL Connector, and MySQL Database. This Login Code In Java is a simple project that uses the Java programming language to connect to a MySQL database.
This article is a way to enhance and develop our skills and logic ideas which is important in practicing the Java programming language which is the most well-known and most usable programming language in many companies.
Inquiries
If you have any questions or suggestions about the Login Page In Java With Source Code, please feel free to leave a comment below.