JDBC Connection Steps

Here we are going to discuss some steps to connect to database in java jdbc. If we want to connect java application with any database then we have to follow 5 steps using jdbc.

Let’s jdbc connection in java with database using some 5 steps.

There are 5 Steps to Java Database Connectivity

  1. Register or load the driver class.
  2. Establish the connection.
  3. Create the statement.
  4. Execute the queries.
  5. Close the connection.

Let’s understand above mentioned jdbc database connection steps one-by-one.

1) Register or load the driver class

The first steps is to register or load the driver class by using forName()  method of Class class.

The forName() method is used to register or load the class dynamically in java.

Syntax of forName() :

public static void forName(String className)throws ClassNotFoundException

Example to load the OracleDriver class


2) Establish the connection 

In this step we will create the connetion object. By using getConnection() method of DriverManager class we can establish the connection with the database.

Syntax of getConnection() :

public static Connection getConnection(String url)throws SQLException

public static Connection getConnection(String url,String name,String password)throws SQLException

Example to establishing connection with oracle database

Connection con = DriverManager.getConnection(


3) Create the statement

Source link

Steps To Connect To Database in Java

Leave a Reply

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