Connect Java With MySQL Database

Connect Java With MySQL

In this comprehensive tutorial we will connect Java with MySQL Database. To connect Java with MYSQL Database we have to follow the following steps : 

Step 1 : Create Java Maven project 

You can create Maven Java Project using IntelliJ IDEA. Just give name of project DBConnect. Then choose build system Maven. And Click on Advanced Settings and write ground id org.codewitharjun or any name you want and ArtifactId DBConnect or any name. 
Create New Java Project
Create New Java Maven Project

Step 2 : Create MySQL Database and Table

Create a MySQL Database using XAMPP

  • Give name of the Database DBConnect.
  • Create a table student with columns age, name, address.
  • Insert data into table. 
Create MySQL database of name DBConnect.
Create MySQL database of name DBConnect.
Create table student
Create table student
Add age, name and address columns in student table
Add age, name and address columns in student table
Insert data into database
Insert data into database

Step 3 : Write Java Code to Connect with MySQL

Now create Java class inside src>main>java with name DBConnect.java. Then write code including the following steps:

  • Register the JDBC driver class.
  • Establish a connection to the MySQL database.
  • Create a statement for executing queries.
  • Execute SQL queries to retrieve data.
  • Close the connection.

DBConnect.java

Step 4 : Add MySQL dependency in pom.xml file.

pom.xml

After adding mysql dependency in pom.xml
After adding mysql dependency in pom.xml

Now just right click on the Java file and click on Run application. The output will be all the datas from the database. 

Output
Output

8 thoughts on “Connect Java With MySQL Database”

  1. você é, na verdade, um webmaster perfeito A velocidade de carregamento do site é incrível Parece que você está fazendo um truque único Além disso O conteúdo é uma obra-prima você realizou uma tarefa maravilhosa neste tópico

  2. Simply wish to say your article is as amazing The clearness in your post is just nice and i could assume youre an expert on this subject Well with your permission let me to grab your feed to keep updated with forthcoming post Thanks a million and please carry on the gratifying work

  3. Your writing has a way of resonating with me on a deep level. I appreciate the honesty and authenticity you bring to every post. Thank you for sharing your journey with us.

  4. I loved as much as youll receive carried out right here The sketch is attractive your authored material stylish nonetheless you command get bought an nervousness over that you wish be delivering the following unwell unquestionably come more formerly again as exactly the same nearly a lot often inside case you shield this hike

  5. Somebody essentially lend a hand to make significantly posts I might state That is the very first time I frequented your web page and up to now I surprised with the research you made to create this particular put up amazing Excellent job

  6. Usually I do not read article on blogs however I would like to say that this writeup very compelled me to take a look at and do it Your writing style has been amazed me Thank you very nice article

Leave a Comment

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

Scroll to Top