Using Java to Connect to Oracle Database 12c Release 2 (12.2)

JDBC is a database access protocol that enables you connect to a database and run SQL statements and queries on the database. The core Java class libraries provide the JDBC APIs, java.sql and javax.sql. However, JDBC is designed to allow vendors to supply drivers that offer the necessary specialization for a particular database.

Note:

Oracle Database 12c Release 2 (12.2) supports JDK 8.

The following sections describe Oracle support for the JDBC standard:

Oracle JDBC Thin Driver

Oracle recommends using the JDBC Thin Driver for most requirements. JDBC-OCI is only needed for OCI-specific features. The Thin driver will work on any system that has a suitable Java virtual machine (JVM).

The JDBC Thin Driver is a pure Java, Type IV driver. It is platform-independent and does not require any additional Oracle software for client-side application development. The JDBC Thin Driver communicates with the server using SQL*Net to access Oracle Database 12c Release 2 (12.2).

You can access the Oracle-specific JDBC features and the standard features by using the oracle.jdbc package.

Oracle JDBC Packages

Oracle support for the JDBC API is provided through the oracle.sql and oracle.jdbc packages. These packages support all Java Development Kit (JDK) releases from JDK 5 till JDK 8.

oracle.sql

The oracle.sql package supports direct access to data in SQL format. This package consists primarily of classes that provide Java mappings to SQL data types and their support classes. Essentially, the classes act as Java wrappers for SQL data. The characters are converted to Java chars and, then, to bytes in the UCS-2 character set.Each of the oracle.sql.* data type classes extends oracle.sql.Datum, a superclass that includes functions and features common to all the data types. Some of the classes are for JDBC 2.0-compliant data types. In addition to data type classes, the oracle.sql package supports classes and interfaces for use with objects and collections.

oracle.jdbc

The interfaces of the oracle.jdbc package define the Oracle extensions to the interfaces in the java.sql package. These extensions provide access to Oracle SQL-format data. They also provide access to other Oracle-specific features, including Oracle performance enhancements.

The key classes and interfaces of this package provide methods that support standard JDBC features and perform tasks such as:

  • Returning Oracle statement objects

  • Setting Oracle performance extensions for any statement

  • Binding oracle.sql.* types into prepared and callable statements

  • Retrieving data in oracle.sql format

  • Getting meta information about the database and result sets

  • Defining integer constants used to identify SQL types