Java JDBC Connection with MySQL Database

Hello guys, Bushan here, welcome back to B2 Tech! Today in this article, I will show you how to create a database in MySQL and get the Connection in Java so let’s get started.



Requirements:

  • MySQL Database or WAMP Server or XAMPP Server
  • Netbeans IDE

The first step is to go to phpMyAdmin, click on the SQL tab, execute the following command,

The second step is to, select the database, execute the following command,

The third step is to create a table, execute the following command,



The fourth step is to create a project inside the Netbeans IDE,

File-> New project-> Java-> Java application, Give a name to your application and click finish

The fifth step is to create a class Connection.java inside the project and write the following code

Connection.java

The sixth step is to add MySQL-connector jar to the project/library



The seventh step is to create JFrame form login.java, inside the project,

login.java

At last call, the connectdb() inside the constructor so that as soon as the application runs/constructor is created, conn object will be initialized.

So at this point, if we run the application we will get the blank JFrame form and an alert message saying that connection has been established.



That’s it for this article, in the next article let’s discuss, how to insert values to MySQL Database.



Love this post?


Help me to buy a cup of coffee/Support us by donating.
All the donations will be going to the website maintenance/improvement.

Pay Now

 

About the author

Bushan Sirgur

Well, I am Bushan Sirgur from Banglore, India. Currently, I am working as a Software Developer in a Service Base Company. I am interested in JAVA/J2EE, Angular 2, JavaScript, jQuery, MongoDB.

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *