Oracle: JDBC (Java Database Connectivity)


JDBC: JDBC (Java DataBase Connectivity) is the specification of the standard application programming interface that provides a standard library for accessing relational databases like MS-Access, Oracle or Sybase. It also provides a common base on which higher-level tools and interfaces can be built. It is an application programming interface that defines how a Java programmer can access the database in tabular format from Java code using a set of standard interfaces and classes written in the Java programming language.

It helps us:
 

  • To connect to a data source, like a database.
  • In sending queries and updating statements to the database
  • Retrieve and process the results received from the database in terms of answers to your query.

                             an1.gif

JDBC API:
The implementation of the JDBC API can only be possible through JDBC Drivers. The API interface is made up of 4 main interfaces:
  • java.sql DriverManager
  • java.sql.Connection
  • java.sql.Statement
  • java.sql.Resultset

Architecture of JDBC Driver:

                              an2.gif

JDBC Drivers: Types of JDBC Drivers:
  • JDBC-ODBC Bridge
  • Native-API partly Java technology-enabled driver
  • A net-protocol fully Java technology-enabled driver
  • A native-protocol fully Java technology-enabled driver

Diagrammatical representation of the different JDBC Drivers:

                         an3.gif

Different types of JDBC SQL Statements
  1. java.sql.Statement: Top most interface which provides basic methods useful for executing SELECT, INSERT, UPDATE and DELETE SQL statements.
  2. java.sql.PreparedStatement: An enhanced verion of java.sql.Statement which allows precompiled queries with parameters.
  3. java.sql.CallableStatement: It allows you to execute stored procedures within a RDBMS which supports stored procedures.

How to use JDBC:
  • First of all load the drivers of JDBC.
  • Secondly define the URL for Connection.
  • Thirdly, establish the connection.
  • Further, create an object of statement.
  • Execute the Query.
  • Now process the results and
  • Close the connection.

Brief description of another widely used interface: ODBC

ODBC:
ODBC is the most widely used interface to access the database. It is a multidatabase API for programs that use SQL statements to access data. With the use of ODBC we can access any data from any application regardless of which database management system (DBMS) is handling the data. We cannot use ODBC directly with Java programs; rather we have to make use of JDBC with ODBC to develop Java database applications.

Difference between JDBC and ODBC:
  • JDBC: is Java Database Connectivity API for making data connection for Data and Java Class.
    ODBC:
    is Object Database Connectivity driver for Microsoft specification and desktop applications.
     
  • JDBC: is designed to keep things simple while allowing advanced capabilities when required.
    ODBC:
    mixes simple and advanced features together and has complex options for simple queries.
     
  • JDBC: JDBC drivers are written in Java and JDBC code is automatically
    installable secure and portable on all platforms.
    ODBC:
    requires manual installation of the ODBC driver manager and driver on all
    client machines.
  • JDBC: JDBC is designed specifically for Java programs
    ODBC:
    ODBC is not depended upon any language.

Architecture of ODBC Driver:

                      an4.gif
                                                                ODBC Driver

Up Next
    Ebook Download
    View all
    Learn
    View all
    F11Research & Development, LLC