0% found this document useful (0 votes)
7 views3 pages

Understanding JDBC: Java Database Connectivity

JDBC, or Java Database Connectivity, is a standard Java API that enables database-independent connectivity between Java applications and various databases. It consists of two layers: the JDBC API for application-to-JDBC Manager connections and the JDBC Driver API for JDBC Manager-to-Driver connections, facilitating communication with databases. The latest version, JDBC 4.0, introduces features such as automatic driver loading and enhanced exception handling, along with a variety of common components like DriverManager, Connection, and Statement for managing database interactions.

Uploaded by

mulymike761
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Understanding JDBC: Java Database Connectivity

JDBC, or Java Database Connectivity, is a standard Java API that enables database-independent connectivity between Java applications and various databases. It consists of two layers: the JDBC API for application-to-JDBC Manager connections and the JDBC Driver API for JDBC Manager-to-Driver connections, facilitating communication with databases. The latest version, JDBC 4.0, introduces features such as automatic driver loading and enhanced exception handling, along with a variety of common components like DriverManager, Connection, and Statement for managing database interactions.

Uploaded by

mulymike761
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

What is JDBC?

JDBC stands for Java Database Connectivity, which is a standard Java API for database-independent
connectivity between the Java programming language and a wide range of databases.
The JDBC library includes APIs for each of the tasks mentioned below that are commonly associated with
database usage.
 Making a connection to a database.
 Creating SQL statements.
 Executing SQL queries in the database.
 Viewing & Modifying the resulting records.
Fundamentally, JDBC is a specification that provides a complete set of interfaces that allows for portable
access to an underlying database. Java can be used to write different types of executables, such as:
 Java Applications
 Java Applets
 Java Servlets
 Java Server Pages (JSP)
 Enterprise JavaBeans (EJB)
All of these different executables are able to use a JDBC driver to access a database, and take advantage of
the stored data. JDBC provides the same capabilities as ODBC, allowing Java programs to contain database
– independent code.

JDBC Architecture
The JDBC API supports both two – tier and three – tier processing models for database access but in general,
JDBC Architecture consists of two layers:
 JDBC API: This provides the application – to – JDBC Manager connection.
 JDBC Driver API: This supports the JDBC Manager – to – Driver connection.
The JDBC API uses a driver manager and database – specific drivers to provide transparent connectivity to
heterogeneous databases.
The JDBC driver manager ensures that the correct driver is used to access each data source. The driver
manager is capable of supporting multiple concurrent drivers connected to multiple heterogeneous
databases.
Following is the architectural diagram, which shows the location of the driver manager with respect to the
JDBC drivers and the Java application:

1
Common JDBC Components
The JDBC API provides the following interfaces and classes:
 DriverManager: This class manages a list of database drivers. Matches connection requests from
the java application with the proper database driver using communication sub protocol. The first
driver that recognizes a certain subprotocol under JDBC will be used to establish a database
Connection.
 Driver: This interface handles the communications with the database server. You will interact
directly with Driver objects very rarely. Instead, you use DriverManager objects, which manages
objects of this type. It also abstracts the details associated with working with Driver objects.
 Connection: This interface with all methods for contacting a database. The connection object
represents communication context, i.e., all communication with database is through connection
object only.
 Statement: You use objects created from this interface to submit the SQL statements to the
database. Some derived interfaces accept parameters in addition to executing stored procedures.
 ResultSet: These objects hold data retrieved from a database after you execute an SQL query using
Statement objects. It acts as an iterator to allow you to move through its data.
 SQLException: This class handles any errors that occur in a database application.

The JDBC 4.0 Packages


The [Link] and [Link] are the primary packages for JDBC 4.0 - this is the latest JDBC version. It offers
the main classes for interacting with your data sources.
The new features in these packages include changes in the following areas:
 Automatic database driver loading.
 Exception handling improvements.

2
 Enhanced BLOB/CLOB functionality.
 Connection and statement interface enhancements.
 National character set support.
 SQL ROWID access.
 SQL 2003 XML data type support.
 Annotations.

Database URL Formulation


A database URL is an address that points to your database. Formulating a database URL is where most of
the problems associated with establishing a connection occurs.
Following table lists down the popular JDBC driver names and database URL.

RDBMS JDBC driver name URL format


MySQL [Link] jdbc:mysql://hostname/ databaseName
ORACLE [Link] jdbc:oracle:thin:@hostname:port No:databaseName
DB2 [Link].DB2Driver jdbc:db2:hostname:port No/databaseName
Sybase [Link] jdbc:sybase:Tds:hostname: port No/databaseName
MS Access [Link] jdbc:ucanaccess://databasePath

All the highlighted part in URL format is static and you need to change only the remaining part as per your
database setup.

You might also like