How to develop JDBC Application

To develop any JDBC application, we follow the following five steps which are as follows:

  1. Load and register the driver class
  2. Creating connection
  3. Creating statement
  4. Executing queries
  5. Closing connection

Load and Register the driver class:

We know database driver is a software which is written according to the JDBC API. There are different ways to register a driver. Here I have presented one way by considering Oracle database that is to send the driver class name directly to forName() method as :



Note: Here we are using type-4 (thin) driver.


Creating connection:

The getConnection() method of DriverManager class is used to establish connection with the database.

Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","password");

Creating statement:

After connecting to the database, we prepare SQL statements by creating an object of type Statement or PreparedStatement or CallableStatement (an interface available in java.sql package) for performing different operations on the database. For example:


Statement st=con.createStatement();

Here by the createStatement() method, we prepare the SQL statement which is assigned in Statement object st.

Executing the SQL statements:

After preparing SQL statements, then we execute the SQL statements by executeQuery() or executeUpdate() or execute() .
executeQuery() returns ResultSet(an interface present in java.sql package) object.
executeUpdate() returns an int value.
execute() returns a Boolean value(true / false).


ResultSet rs = rs.executeQuery("select * from employee");

After executing this statement, the results are stored in rs.

Closing connection:

By closing connection object statement and ResultSet will be closed automatically. The close() method of Connection interface is used to close the connection.



Our Services:

Java Training | Python Training | Machine Learning with Python Training | Deep Learning with Python Training | Data Science with Python Training | Projects

Silansoftware Pvt.Ltd, BBSR
Call to: 0674-2361252