Java Database Connectivity (JDBC)


Java Database Connectivity

Java Database Connectivity (JDBC) & 7 steps to connect Java application with RDBMS

Java Database connectivity is basically done to access the database by client in the programming language Java.

Database is the place where all the users data is stored, the connection of Java application with database to query and update data in database is called JDBC.

7 steps to connect a Java application with RDBMS(using MySql)

RDBMS:- A relational database management system is a database management system based on relational model. RDBMSs have been a common choice for the storage of information in databases used for financial records, manufacturing and logistical information, personnel data, and other applications since the 1980s.

Step 1:- Import the package

Syntax:-

import java.sql.*;

Step 2:- Load & Register the driver

Syntax:-

Class.forName ("com.mysql.jdbcDriver");

Step 3:- Establish connection

Syntax:-

Connection con=DriverManager.getConnection ("jdbc:mysql://localhost:3306/test","username","password");

First one in inverted comma is URL of database.

Second username is "root" by default.

Password is same as you have set in your database.

Step 4:- Create statement

Syntax:-

Statement stat=con.createStatement ();

Step 5:- Execute query

Syntax:-

stat.execute("insert into user (name) values ('"+name+"')");

Here "user" is name of the table in database.

"name" is field in database where value taken from textfield name (web page) will be stored.

Step 6:- Process the result set

Syntax:-

ResultSet rs=stat.executeQuery ("Select *from user");

Here * means selecting all the data present in user table in database.

Step 7:- Close connection

Syntax:-

con.Close ();

 


Also Read- Top 10 Books on Machine Learning with Python 


 

Custom Search

%d bloggers like this: