JDBC know as Java Database Connectivityprovides set of api or standard library for accessing relational databases. Java programs interact with any SQL-compliant database using this api.
JDBC API achieve following tasks:
- Allow to establish connection with supported database
- Sql Query creation
- Method to create and execute stored queries
- Metadata look up
The JDBC API supports both three-tier and two-tier models for database access but consists of two layers:
- JDBC API: This allows connection between application and JDBC Manager.
- JDBC Driver API: This allows Driver Connection to JDBC Manager.
The JDBC API uses drivers which are database-specific and driver manager to provide connectivity to databases.
The JDBC driver manager communicates with vendor-specific driver that performs real communication with database.
JDBC-ODBC Bridge plus ODBC Driver (Type 1): Driver use ODBC driver to connect to database servers.
Native API partly Java technology-enabled driver (Type 2): Driver converts JDBC class to client API for the RDBMS server.
Pure Java Driver for Database Middleware (Type 3): Driver sends the JDBC calls to middleware server to connect different type of databases.
Direct-to-Database Pure Java Driver (Type 4): Driver allows the JDBC calls over the network protocol using the database server.
Common JDBC Components:
The JDBC API has following classes and interfaces:
- Driver Manager:Database drivers list are managed by this class.
- Driver:It is an Interface to communicatewith database server.
- Connection :It is an interface having all methods for contacting with database
- Statement:The objects created interface to SQL statements to database.
- ResultSet:The objects holds data retrieved from database after executing SQL query Statement objects.
- SQLException: The class handles any errors occurring in database application.
The JDBC 4.1 Packages
The JDBC 4.1 is a primary package which includes java.sql and javax.sql.
New features in 4.1 includes
- The ability to automatically close resources of type
Statement with try-with-resources statement.
- RowSet 1.1: The introduction of the
RowSetFactory interface and the
RowSetProvider class, which enable you to create all types of row sets supported by your JDBC driver.