When we are developing a java program which needs to store data, we should connect a database with the program. In this article we will learn the way of connecting MySQL database server along with java program.
I choose intellij IDEA development environment to run the java codes.
U should have,
- Intellij IDEA development environment
- MySQL database management system
installed on your computer.
And also you should download the JDBC application programming interface in order to access the database. It can be use to build the java database connection. You may download the file using following link.
MySQL :: Download MySQL Installer
MySQL Installer provides an easy to use, wizard-based installation experience for all your MySQL software needs…
Then create a project using intellij idea and make a folder inside your project. Name it as lib and store the bin.jar file inside the lib folder which is extracted from downloaded JDBC file. Then go to the following path and export the bin.jar file to the dependencies.
File → Project Structure → Modules → Dependencies
And do as follows.
Now we can go see the way to build the connection between java program and the database.
First create a database and use its name to the URL.
Using the database and creating table.
Inserting records to the database
Updating new values to the database
Deleting record from database
Using above basic knowledge we can use other complex sql queries along with the java programs.