TechSupportNepTechSupportNep - Programming & Tech

  • Home
  • C#.NET
  • PHP
  • JAVA
  • Python
  • ASP.NET
  • VB.NET
  • Android
  • C
  • Tech
    • Tech News
  • Patreoner
TechSupportNep
  • Home
  • Programming
  • JAVA
  • How to Create Multiple User Login Form in java using MySQL Database and NetBeans IDE?
JAVA

How to Create Multiple User Login Form in java using MySQL Database and NetBeans IDE?

By Er. Ran Bahadur B.K. Last updated Aug 15, 2021
3 8,819
Share

Hello guyz, if you are looking for the tutorial that shows how to create a multiple user login form in java using MySQL database and redirect to different form based on user role, then you are in the right tutorial.

In the process of solving real world problem, you may need to develop such a system which may have multiple number of user of a single system and when each user login to the system they must need to access only the certain features of an application which means they don’t need to access all the feature. In general the administrator have access to all the features and normal user may not have. So, this tutorial is all about this.

If you don’t know how to create login form in java, first of all, you need to read these tutorials:

Login form in java using SQL Server Database: HERE

Login form in java using MySQL Database: HERE

After reading these tutorial, you will understand basics about java, JDK, JRE, environment variable, required server application etc.

So, i consider that you have the basic knowledge of all these things, and required application in your system. But specifically, in this tutorial we need these two application.

Download NetBeans IDE: HERE

Download WAMP Server: HERE

STEPS:

 

1.Now open Netbeans IDE and click on file > new project. Select categories as java and project as java application from that window:

How to Create Login From in Java

2. Click next and then give your project name and then click finished.

3. Now right click on your project and select new > JFrame Form:

4. After this new window will appear from this window drag Panel and extend it, and drag three label, two Text Field, one Button ,one ComboBox and drop to the jframe from. Change the name of the label to username, password and select user type. Change the variable name of the Text Field by right clicking it and named it as txtuser and txtpass respectively. Change the Button text to Login. And right click the combobox click on properties and click on model, add the item there like admin, user etc. which will looks like this:

How to Create Multiple User Login Form in java?

And finally our login form will looks like the following one:

How to Create Multiple User Login Form in java?

5. After download and installing wamp server open it, and then open your localhost, for this open up your any browsing software and type localhost or 127.0.0.1 in the address bar. Then new page will appear then scroll down and find phpmyadmin and click on that. Then you will be able to see the login page. Login in by entering username and password (Default username is root and password is empty). And then click on new and create one database having any name you want and the click OK, then create table having three field in and click on go. After that, you need to insert the field name like: username, password and usertype. and then select the length (like 50, 30, 100 etc) as well as data type (recommend varchar) as your requirement and then click on save. OR You can watch the video for this designing part, you may understand better in video.

some screenshot of creating database are:

How to Create Multiple User Login Form in java?

How to Create Multiple User Login Form in java?

How to Create Multiple User Login Form in java?

NOTE: we have to insert username, password and usertype in our database. So, for this, Click on insert tab and insert username, password and usertype as:

How to Create Multiple User Login Form in java?

6. Declare following variable inside the class your jframe, for this select source from the top of the jframe.

Connection con = null;
PreparedStatement pst=null;
ResultSet rs = null;

7. Now double click the Login button and write the following code:

try{
String query = "SELECT * FROM `multiuserlogin` WHERE username=? and password=? and usertype=?";
con = DriverManager.getConnection("jdbc:mysql://localhost/multiuserlogin", "root", "");
pst=con.prepareStatement(query);
pst.setString(1, txtuser.getText());
pst.setString(2, txtpass.getText());
pst.setString(3, String.valueOf(jComboBox1.getSelectedItem()));
rs=pst.executeQuery();
if(rs.next()){
JOptionPane.showMessageDialog(this, "username and password matched and you are logined as "+rs.getString("usertype"));
if(jComboBox1.getSelectedIndex()==0){
admin a = new admin();
a.setVisible(true);
this.setVisible(false);
}
else{
user u = new user();
u.setVisible(true);
this.setVisible(false);
}}
else{
JOptionPane.showMessageDialog(this, "username and password do not matched");

}
}
catch(Exception ex){
JOptionPane.showMessageDialog(this, ex.getMessage());

}

8. Now you need to have MySQL connector for java so download it. Click Here and Add this jar file in your project libraries folder by right clicking libraries >click add jar. Select downloaded jar file and click open.

How to Create Multiple User Login Form in java?

9. To run this program you need to right click on your jframe and click run file as below:

How to Create Multiple User Login Form in java?

Now enter right username, password  and click Login.

 

If you like this tutorial share this tutorials with your friends or in any java group so that they will know about this tutorial.

If you are confused then you can watch the following video:

 

Continue Reading
admin and user login in javacreate multiuser login form in javacreate multiuser login form in java using mysql databaseHow do I create a multi-user login form in Javahow to create admin and user login in javahow to create admin user in javahow to create multi user login java netbeansHow To Make Form login multiple user perfect UI Java NetbeansJava Swing Multi-User Login in Netbeans and MySQL DatabaseMulti User Login java
3 8,819
Share FacebookTwitterReddItWhatsAppPinterestEmail
Er. Ran Bahadur B.K.60 posts 56 comments

Ran Bahadur B.K. is the owner of TechSupportNep who is working with the aim of providing the quality Technology content. He is creating Tech and Programming videos, you can see all them in his YouTube Channel(https://www.youtube.com/TechSupportNep). He is also working with some company.

Prev Post

How to Create Quiz Application in Java Using MySQL Database and NetBeans IDE?[With Source Code]

Next Post

How to Create Multi User Login Form in PHP using MySQL Database?

Show Comments (3)
Help Needed

This website is free of annoying ads. We want to keep it like this. You can help with your support:

Donate!

The need for Support! Why to Support?

If you need your own website? contact me!
erranbahadurbk
Fiverr
Seller
Hello there,This is me Ran Bahadur B.K., A graduated computer engineer. I have 3+ years of work experience in wordpress design and development. I have strong knowledge of HTML, CSS and PHP which are the three ingredients of web development. Currently i am working with the software company so i also have experience in desktop apps and mobile apps development.

Latest

Python

How to Create Login Application in Python using SQLite Database?

How to use View Binding in Android?

Windows 10 Build 1909 Features that you should know.

How to Create a Complete Login and Forgot Password System in java ?

Prev Next 1 of 15
  • About us
  • Contact us
  • Privacy Policy
  • Disclaimer
© 2022 All Rights Reserved.
Website By: Ran Bahadur B.K.