RunCodesRunCodes - Programming & Tech

  • Home
  • C#.NET
  • PHP
  • JAVA
  • Python
  • ASP.NET
  • VB.NET
  • Android
  • C
  • Tech
    • Tech News
  • Patreoner
RunCodes
  • Home
  • Programming
  • JAVA
  • How to Create a Login Form in Java using MySQL Database and NetBeans IDE?[With Source Code]
JAVA

How to Create a Login Form in Java using MySQL Database and NetBeans IDE?[With Source Code]

By Er. Ran Bahadur B.K. Last updated Aug 15, 2021
5 12,744
Share

Hello guyz, Today i am here with totally new topic. Today i am going to write about how to create a login form in java-9 using MySQL Databse and NetBeans IDE 8.1. This is a simple project in java but this is the most important stage you have to learn if you want to create a more complex project in java. This article will show you how to connect NetBeans IDE to the MySQL Database, how to drag and drop controls like panel, textbox, label and Button. Download Netbeans IDE and any Server Application.

i am using wamp server so:

Wamp server: http://www.wampserver.com/en/

Netbeans IDE: https://netbeans.org/downloads/

It is important for all project to connect them to the database to access some files or to store some information back to the database. So, This article will show you all the basic things that you should know to create a big project. I am going to explain each and every steps here:

1. First of all you have to install Java JDK or JRE in your PC, it’s better in install JDK so download and install it from here: https://jdk9.java.net/download/

2. after you install it, change the environment variable of your system by going: Control panel > System and then click on advance system setting from left side of that window. After clicking on advance system setting a new window will appear then you have to click on Environment Variables. After this, you will obtain new window and you will see the path in the bottom of the window and double click on the path. After this click on new tab and copy the java path from C where you have install the java. In my case my java path is this : C:\Program Files\Java\jdk-9\bin\ and then click on OK. which will looks like this:

How to Create Login From in Java

3. 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

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

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

How to Create Login From in Java

6. After this new window will appear from this window drag Panel and extend it, and drag two label, two Text Field, one Button and drop to the jframe from. change the name of the label to username and password and change the variable name of the Text Field by right clicking it and named it as user and pass respectively which will looks like this:

How to Create Login From in Java

7. 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 two field in and click on go. After that, you need to insert the field name like: username and password. and then select the length as well as data type as your requirement and then click on save. You can watch the video for this designing part, you may understand better in video.

8. Now you need to have MySQL connector for java so download it.

https://dev.mysql.com/downloads/connector/j/

9. Now double click on login button, after doing this you will go to the source code file. Scroll up and find the main class of your project and under that class declare these variable:

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

10. Goto the jframe form and then double click on the login button and write the following piece of code and run your project by right clicking the the jframe form from the project explorer and then click on run file but before running your file you need to add the MySQL Connector for java. So right click on the libraries folder from the project explorer, then click on add JAR/folder and select that downloaded jar file and click on add.

String sql="select * from login where username=? and password=?";
try{
con = DriverManager.getConnection("jdbc:mysql://localhost/testsql","root","");
pst=con.prepareStatement(sql);
pst.setString(1, user.getText());
pst.setString(2,pass.getText());
rs=pst.executeQuery();
if(rs.next())
{
JOptionPane.showMessageDialog(null,"username and password matched");

}
else
{
JOptionPane.showMessageDialog(null, "username and password do not matched");
}
}
catch(SQLException | HeadlessException ex)
{
JOptionPane.showMessageDialog(null,ex);
}

That’s it guyz.

if you have any confusion, you can watch the following video:

 

Continue Reading
connecting to database in javaCreate Login Form in Java using NetBeans and sql servercreating a login form with java connected to mysqlHow To Create Login Form In Java With MySQL DatabaseHow To Create Login Form With MySQL Databasejava connect to mysql databasejava login form with mysql db connectivityjava mysql examplejdbc mysql urllogin form java codemysql database connection in javamysql in javamysql jdbc connection stringmysql jdbc example
5 12,744
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 User Registration Form using PHP and MySQL? [With Source Code]

Next Post

How to Send Free SMS From Gmail?

You might also like More from author
JAVA

Create Simple Login Form in Java Without Connecting to Database[With Source Code]

JAVA

How to Create Login Form in Java-9 using SQL Server and NetBeans IDE?[With Source…

Show Comments (5)
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.