1 Introducing JDBC

Java Database Connectivity (JDBC) is a Java standard that provides the interface for connecting from Java to relational databases. JDBC is based on the X/Open SQL Call Level Interface (CLI). JDBC 4.0 complies with the SQL 2003 standard.

The JDBC standard is defined and implemented through the standard java.sql interfaces. This enables individual providers to implement and extend the standard with their own JDBC drivers. This chapter provides an overview of the Oracle implementation of JDBC, covering the following topics:

Note:

Oracle Database 20c is available only for limited Cloud preview and not for production use. Likewise, the Oracle JDBC Driver 20c is not available for download.

1.1 Overview of Oracle JDBC Drivers

In addition to supporting the standard JDBC application programming interfaces (APIs), Oracle drivers have extensions to support Oracle-specific data types and to enhance performance.

Oracle provides the following JDBC drivers:

  • Thin driver

    The JDBC Thin driver is a pure Java, Type IV driver that can be used in applications. It is platform-independent and does not require any additional Oracle software on the client-side. The JDBC Thin driver communicates with the server using Oracle Net Services to access Oracle Database.

    The JDBC Thin driver enables a direct connection to the database by providing an implementation of Oracle Net Services on top of Java sockets. The driver supports the TCP/IP protocol and requires a TNS listener on the TCP/IP sockets on the database server.

    Note:

    Oracle recommends you to use the Thin driver unless you have a feature that is supported only by a specific driver.

  • Oracle Call Interface (OCI) driver

    It is used on the client-side with an Oracle client installation. It can be used only with applications.

    The JDBC OCI driver is a Type II driver used with Java applications. It requires platform-specific OCI libraries. It supports all installed Oracle Net adapters, including interprocess communication (IPC), named pipes, TCP/IP, and Internetwork Packet Exchange/Sequenced Packet Exchange (IPX/SPX).

    The JDBC OCI driver, written in a combination of Java and C, converts JDBC invocations to calls to OCI, using native methods to call C-entry points. These calls communicate with the database using Oracle Net Services.

    The JDBC OCI driver uses the OCI libraries, C-entry points, Oracle Net, core libraries, and other necessary files on the client computer where it is installed.

    OCI is an API that enables you to create applications that use the native procedures or function calls of a third-generation language to access Oracle Database and control all phases of the SQL statement processing.

  • Server-side Thin driver

    It is functionally similar to the client-side Thin driver. However, it is used for code that runs on the database server and needs to access another session either on the same server or on a remote server on any tier.

    The JDBC server-side Thin driver offers the same functionality as the JDBC Thin driver that runs on the client-side. However, the JDBC server-side Thin driver runs inside Oracle Database and accesses a remote database or a different session on the same database for use with Java in the database.

    This driver is useful in the following scenarios:

    • Accessing a remote database server from an Oracle Database instance acting as a middle tier

    • Accessing an Oracle Database session from inside another, such as from a Java stored procedure

    The use of JDBC Thin driver from a client application or from inside a server does not affect the code.

  • Server-side internal driver

    It is used for code that runs on the database server and accesses the same session. That is, the code runs and accesses data from a single Oracle session.

    The JDBC server-side internal driver supports any Java code that runs inside Oracle Database, such as in a Java stored procedure, and accesses the same database. It lets the Oracle Java Virtual Machine (Oracle JVM) to communicate directly with the SQL engine for use with Java in the database.

    The JDBC server-side internal driver, the Oracle JVM, the database, and the SQL engine all run within the same address space, and therefore, the issue of network round-trips is irrelevant. The programs access the SQL engine by using function calls.

    Note:

    The server-side internal driver does not support the cancel and setQueryTimeout methods of the Statement class.

    The JDBC server-side internal driver is fully consistent with the client-side drivers and supports the same features and extensions.

The following figure illustrates the architecture of Oracle JDBC drivers and Oracle Database.

Figure 1-1 Architecture of Oracle JDBC Drivers and Oracle Database

Description of Figure 1-1 follows
Description of "Figure 1-1 Architecture of Oracle JDBC Drivers and Oracle Database"

1.2 Choosing the Appropriate Driver

Consider the following when choosing a JDBC driver for your application or applet:

  • In general, unless you need OCI-specific features, such as support for non-TCP/IP networks, use the JDBC Thin driver.

  • If you want maximum portability and performance, then use the JDBC Thin driver. You can connect to Oracle Database from an application using the JDBC Thin driver.

  • If you want to use Lightweight Directory Access Protocol (LDAP) over Secure Sockets Layer (SSL)/Transport Layer Security (TLS), then use the JDBC Thin driver.

  • If you are writing a client application for an Oracle client environment and need OCI-driver-specific features, such as support for non-TCP/IP networks, then use the JDBC OCI driver.

  • For code that runs in the database server and needs to access a remote database or another session within the same database instance, use the JDBC server-side Thin driver.

  • If your code runs inside the database server and needs to access data locally within the session, then use the JDBC server-side internal driver to access that server.

1.3 Feature Differences Between JDBC OCI and Thin Drivers

The following table lists the features that are specific either to the JDBC OCI or the JDBC Thin driver in Oracle Database Release 20c.

Table 1-1 Feature Differences Between the JDBC OCI Driver and the JDBC Thin Driver

JDBC OCI Driver JDBC Thin Driver

OCI connection pooling

NA

NA

Default support for Native XA

Transparent Application Failover (TAF)

NA

NA

Application Continuity

NA

Transaction Guard

NA

Support for row count per iteration for array DML

NA

SHA-2 Support in Oracle Advanced Security

oraaccess.xml configuration file settings

NA

NA

Oracle Advanced Queuing

NA

Continuous Query Notification

NA

Support for the O7L_MR client ability

NA

Support for promoting a local transaction to a global transaction

Note:

  • The OCI optimized fetch feature is internal to the JDBC OCI driver and not applicable to the JDBC Thin driver.

  • Some JDBC OCI driver features, inherited from the OCI library, are not available in the Thin JDBC driver.

1.4 Environments and Support

This section provides a brief description of the tools and environments that you need to run a JDBC application.

1.4.1 Supported JDK and JDBC Versions

In Oracle Database 20c, all the JDBC drivers are compatible with JDK 8, JDK 9, JDK 10, and JDK 11, and the ojdbc8.jar and ojdbc10.jar files provide the support to the respective JDK versions.

When to Use ojdbc8.jar File

Use the ojdbc8.jar file when you compile your code with JDK 8, JDK 9, and JDK 11.

When to Use ojdbc10.jar File

Use the ojdbc10.jar file when you compile your code with JDK 10 and JDK 11.

1.4.2 JNI and Java Environments

The JDBC OCI driver uses the standard Java Native Interface (JNI) to call OCI C libraries. You can use the JDBC OCI driver with Java Virtual Machines (JVMs), in particular, with Microsoft and IBM JVMs.

1.4.3 JDBC and IDEs

The Oracle JDeveloper Suite provides developers with a single, integrated set of products to build, debug, and deploy component-based database applications for the Internet. The Oracle JDeveloper environment contains integrated support for JDBC, including the JDBC Thin driver and the native OCI driver. The database component of Oracle JDeveloper uses the JDBC drivers to manage the connection between the application running on the client and the server.

1.4.4 Availability on Maven Central

All supported releases of the Oracle JDBC drivers, including 19.6.0.0, 19.3.0.0, 18.3.0.0, 12.2.0.1, and 11.2.0.4, are available on Maven Central. So, you can consider Maven Central as a distribution center for the Oracle JDBC drivers and companion JAR files.

Group IDs for JDBC Drivers and Companion JAR Files on Maven Central

All Oracle Database artifacts on Maven Central reside under the same umbrella com.oracle.database as shown in the following image:

Maven Central Location for Oracle Database Artifacts

You can find the Oracle Database Artifacts under their specific focus area. For example, JDBC, XML, security, high-availability (HA), NLS, observability, and so on. The following table lists the group IDs of the JDBC drivers and the companion JAR files:

Group ID Corresponding JAR Files
com.oracle.database.jdbc ojdbc10.jar, ojdbc8.jar, ojdbc6.jar, ojdbc5.jar, ucp.jar, ojdbc10dms.jar, ojdbc8dms.jar, ojdbc6dms.jar, ojdbcd5dms.jar
com.oracle.database.jdbc.debug ojdbc10_g.jar, ojdbc8_g.jar, ojdbc6_g.jar, ojdbc5_g.jar, ojdbc10dms_g.jar, ojdbc8dms_g.jar, ojdbc6dms_g.jar, ojdbc5dms_g.jar
com.oracle.database.security osdt_core.jar, osdt_cert.jar, oraclepki.jar
com.oracle.database.ha ons.jar, simplefan.jar
com.oracle.database.nls orai18n.jar
com.oracle.database.xml xdb.jar, xdb6.jar, xmlparserv2.jar
com.oracle.database.observability dms.jar

Note:

  • The ojdbc8dms.jar and ojdbc10dms.jar files provides complete support for the Dynamic Monitoring System (DMS) and limited support for the java.util.logging package.
  • xdb6.jar is a legacy name. The new name is xdb.jar.

Managing Dependencies on Maven Central with GAVs

You can manage the JDBC and UCP dependencies in the pom.xml file of your project by using the corresponding group ID, artifact ID, and the version (GAV), as defined in this section. For example, the following GAV pulls the ojdbc10.jar, ucp.jar, oraclepki.jar, osdt_core.jar, osdt_cert.jar, ons.jar, and simplefan.jar from the 19.3 release:

<dependency>
      <groupId>com.oracle.database.jdbc</groupId>
      <artifactId>ojdbc10</artifactId>
      <version>19.3.0.0</version>
    </dependency>

Similarly, the following GAV pulls the orai18n.jar file from the 19.3.0.0 release:

<dependency>
      <groupId>com.oracle.database.nls</groupId>
      <artifactId>orai18n</artifactId>
      <version>19.3.0.0</version>
    </dependency>

1.5 Feature List

This section lists the supported features and the corresponding versions in which they were first supported in the JDBC OCI driver and the JDBC Thin driver.

Table 1-2 Feature List

Feature JDBC OCI JDBC Thin

TimeZone Patching

11.2

11.2

Secure LOB Support

11.2

11.2

LOB prefetch Support

11.2

11.2

Network Connection Pool

 

11.2

Column Security Support

 

11.2

XMLType Queue Support (AQ)

 

11.2

Notification Grouping (AQ and DCN)

 

11.2

SimpleFAN

11.2

11.2

Application Continuity

12.2

12.1

Transaction Guard

12.2

12.1

SQL Statement Translation

 

12.1

Database Resident Connection Pooling

12.1

12.1

SHA-2 Support in Oracle Advanced Security

 

12.1

Invisible Columns Support

12.1

12.1

Support for PL/SQL Package Types as Parameters

12.1

12.1

Support for Monitoring of Database Operations

12.1

12.1

Support for Increased Length Limit for Various Data Types

12.1

12.1

Implicit Results Support

12.1

12.1

Support for row count per iteration for array DML

 

12.1

oraaccess.xml configuration file settings

12.1

 
Transparent Application Continuity NA 18c
Support for verifying JSON Data 18c 18c
Support for Lightweight Connection Validation   18c
Support for REF CURSOR as IN bind variables 18c 18c
Support for Key Store Service   18c
Easy Connect Plus (Easy Connect Naming Syntax Improvements)   19c

Note:

  • The following features of JDBC drivers were introduced in releases earlier than release 11.2:
    • NLS Support
    • New Statement Caching API
    • Row Prefetch
    • Java Native Interface
    • Native LOB
    • Associative Arrays/index-by-table
    • Implicit Statement Caching
    • Explicit Statement Caching
    • Temporary LOBs
    • Object Type Inheritance
    • Multilevel Collections
    • oracle.jdbc Interfaces
    • Native XA
    • OCI Connection Pooling
    • Transparent Application Failover
    • Implicit Connection Cache
    • Fast Connection Failover
    • Connection Wrapping
    • DMS
    • Service Names in URLs
    • Set Statement Parameters by Name
    • End-to-End Tracing
    • Web RowSet
    • Proxy Authentication
    • Run-time Connection Load Balancing
    • Extended setXXX and getXXX for LOBs
    • XA Connection Cache
    • DML Returning
    • JSR 114 RowSets
    • SSL/TLS Encryption
    • SSL/TLS Authentication
    • AES Encryption
    • SHA1 Hash
    • Radius Authentication
    • Kerberos Authentication
    • ANYDATA and ANYTYPE types
    • Native AQ
    • Query Change Notification
    • Database startup and shutdown
    • Factory methods for data types
    • Buffer Cache
    • Secure Files
    • Diagnosability
    • Server Result Cache
    • Universal Connection Pool
  • The ConnectionCacheImpl connection cache feature is deprecated since Oracle Database 10g.
  • The Implicit Connection Cache feature is desupported now.