JDBC Developer's Guide - Oracle

[Pages:54]Oracle? Database

JDBC Developer's Guide

19c

E96471-09 December 2021

Oracle Database JDBC Developer's Guide, 19c

E96471-09

Copyright ? 1999, 2021, Oracle and/or its affiliates.

Primary Author: Tulika Das

Contributing Authors: Brian Martin, Venkatasubramaniam Iyer, Elizabeth Hanes Perry, Brian Wright, Thomas Pfaeffle

Contributors: Kuassi Mensah, Douglas Surber, Paul Lo, Ed Shirk, Tong Zhou, Jean de Lavarene, Rajkumar Irudayaraj, Ashok Shivarudraiah, Angela Barone, Rosie Chen, Sunil Kunisetty, Joyce Yang, Mehul Bastawala, Luxi Chidambaran, Vidya Nayak, Srinath Krishnaswamy, Swati Rao, Pankaj Chand, Aman Manglik, Longxing Deng, Magdi Morsi, Ron Peterson, Ekkehard Rohwedder, Catherine Wong, Scott Urman, Jerry Schwarz, Steve Ding, Soulaiman Htite, Anthony Lai, Prabha Krishna, Ellen Siegal, Susan Kraft, Sheryl Maring

This software and related documentation are provided under a license agreement containing restrictions on use and disclosure and are protected by intellectual property laws. Except as expressly permitted in your license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license, transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means. Reverse engineering, disassembly, or decompilation of this software, unless required by law for interoperability, is prohibited.

The information contained herein is subject to change without notice and is not warranted to be error-free. If you find any errors, please report them to us in writing.

If this is software or related documentation that is delivered to the U.S. Government or anyone licensing it on behalf of the U.S. Government, then the following notice is applicable:

U.S. GOVERNMENT END USERS: Oracle programs (including any operating system, integrated software, any programs embedded, installed or activated on delivered hardware, and modifications of such programs) and Oracle computer documentation or other Oracle data delivered to or accessed by U.S. Government end users are "commercial computer software" or "commercial computer software documentation" pursuant to the applicable Federal Acquisition Regulation and agency-specific supplemental regulations. As such, the use, reproduction, duplication, release, display, disclosure, modification, preparation of derivative works, and/or adaptation of i) Oracle programs (including any operating system, integrated software, any programs embedded, installed or activated on delivered hardware, and modifications of such programs), ii) Oracle computer documentation and/or iii) other Oracle data, is subject to the rights and limitations specified in the license contained in the applicable contract. The terms governing the U.S. Government's use of Oracle cloud services are defined by the applicable contract for such services. No other rights are granted to the U.S. Government.

This software or hardware is developed for general use in a variety of information management applications. It is not developed or intended for use in any inherently dangerous applications, including applications that may create a risk of personal injury. If you use this software or hardware in dangerous applications, then you shall be responsible to take all appropriate fail-safe, backup, redundancy, and other measures to ensure its safe use. Oracle Corporation and its affiliates disclaim any liability for any damages caused by use of this software or hardware in dangerous applications.

Oracle, Java, and MySQL are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.

Intel and Intel Inside are trademarks or registered trademarks of Intel Corporation. All SPARC trademarks are used under license and are trademarks or registered trademarks of SPARC International, Inc. AMD, Epyc, and the AMD logo are trademarks or registered trademarks of Advanced Micro Devices. UNIX is a registered trademark of The Open Group.

This software or hardware and documentation may provide access to or information about content, products, and services from third parties. Oracle Corporation and its affiliates are not responsible for and expressly disclaim all warranties of any kind with respect to third-party content, products, and services unless otherwise set forth in an applicable agreement between you and Oracle. Oracle Corporation and its affiliates will not be responsible for any loss, costs, or damages incurred due to your access to or use of third-party content, products, or services, except as set forth in an applicable agreement between you and Oracle.

Contents

Preface

Audience

xxiv

Documentation Accessibility

xxiv

Related Documents

xxiv

Conventions

xxv

Changes in This Release for Oracle Database JDBC Developer's Guide

Changes in Oracle Database 19c

xxx

Part I Overview

1 Introducing JDBC

1.1 Overview of Oracle JDBC Drivers

1-1

1.2 Choosing the Appropriate Driver

1-3

1.3 Feature Differences Between JDBC OCI and Thin Drivers

1-4

1.4 Environments and Support

1-4

1.4.1 Supported JDK and JDBC Versions

1-5

1.4.2 JNI and Java Environments

1-5

1.4.3 JDBC and IDEs

1-5

1.5 Feature List

1-5

2 Getting Started

2.1 Version Compatibility for Oracle JDBC Drivers

2-1

2.2 Verifying a JDBC Client Installation

2-2

2.2.1 Checking the Installed Directories and Files

2-3

2.2.2 Checking the Environment Variables

2-4

2.2.3 Ensuring that the Java Code Can Be Compiled and Run

2-5

2.2.4 Determining the Version of the JDBC Driver

2-5

2.2.5 Testing the JDBC and Database Connection

2-6

iii

2.3 Basic Steps in JDBC 2.3.1 Importing Packages 2.3.2 Opening a Connection to a Database 2.3.3 Creating a Statement Object 2.3.4 Running a Query and Retrieving a Result Set Object 2.3.5 Processing the Result Set Object 2.3.6 Closing the Result Set and Statement Objects 2.3.7 Making Changes to the Database 2.3.8 About Committing Changes 2.3.8.1 Changing Commit Behavior 2.3.9 Closing the Connection

2.4 Sample: Connecting, Querying, and Processing the Results 2.5 Support for Invisible Columns 2.6 Support for Verifying JSON Data 2.7 Support for Implicit Results 2.8 Support for Lightweight Connection Validation 2.9 Support for Deprioritization of Database Nodes 2.10 Support for Oracle Connection Manager in Traffic Director Mode

2.10.1 Modes of Running Oracle Connection Manager in Traffic Director Mode 2.10.2 Benefits of Oracle Connection Manager in Traffic Director Mode 2.10.3 Restrictions for Oracle Connection Manager in Traffic Director Mode 2.11 Support for Memoptimized Rowstore Fast Ingest 2.12 Stored Procedure Calls in JDBC Programs 2.12.1 PL/SQL Stored Procedures 2.12.2 Java Stored Procedures 2.13 About Processing SQL Exceptions

Part II Oracle JDBC

3 JDBC Standards Support

3.1 Support for JDBC 2.0 Standard 3.1.1 Data Type Support 3.1.2 Standard Feature Support 3.1.3 Extended Feature Support 3.1.4 Standard versus Oracle Performance Enhancement APIs

3.2 Support for JDBC 3.0 Standard 3.2.1 Overview of Transaction Savepoints 3.2.1.1 About Creating a Savepoint 3.2.1.2 About Rolling Back to a Savepoint 3.2.1.3 About Releasing a Savepoint

2-7 2-8 2-9 2-10 2-10 2-10 2-11 2-11 2-13 2-14 2-15 2-15 2-16 2-18 2-19 2-21 2-23 2-23 2-24 2-25 2-27 2-27 2-28 2-28 2-29 2-29

3-1 3-2 3-2 3-2 3-2 3-2 3-3 3-3 3-4 3-4

iv

3.2.1.4 About Checking Savepoint Support 3.2.1.5 Savepoint Notes 3.2.2 Retrieval of Auto-Generated Keys 3.2.2.1 java.sql.Statement 3.2.2.2 Sample Code 3.2.2.3 Limitations of Auto-Generated Keys 3.2.3 JDBC 3.0 LOB Interface Methods 3.2.4 Result Set Holdability 3.3 Support for JDBC 4.0 Standard 3.3.1 Wrapper Pattern Support 3.3.2 SQLXML Type 3.3.3 Enhanced Exception Hierarchy and SQLException 3.3.4 The RowId Data Type 3.3.5 LOB Creation 3.3.6 National Language Character Set Support 3.4 Support for JDBC 4.1 Standard 3.4.1 setClientInfo Method 3.4.2 getObject Method 3.5 Support for JDBC 4.2 Standard

4 Oracle Extensions

4.1 Overview of Oracle Extensions 4.2 Features of the Oracle Extensions

4.2.1 Database Management Using JDBC 4.2.2 Support for Oracle Data Types 4.2.3 Support for Oracle Objects 4.2.4 Support for Schema Naming 4.2.5 DML Returning 4.2.6 PL/SQL Associative Arrays 4.3 Oracle JDBC Packages 4.3.1 Package oracle.sql 4.3.2 Package oracle.jdbc 4.4 Oracle Character Data Types Support 4.4.1 SQL CHAR Data Types 4.4.2 SQL NCHAR Data Types 4.4.3 Class oracle.sql.CHAR 4.5 Additional Oracle Type Extensions 4.5.1 Oracle ROWID Type 4.5.2 Oracle REF CURSOR Type Category 4.5.3 Oracle BINARY_FLOAT and BINARY_DOUBLE Types

3-4 3-4 3-4 3-5 3-5 3-6 3-6 3-6 3-6 3-7 3-8 3-10 3-10 3-10 3-11 3-11 3-12 3-13 3-14

4-1 4-1 4-2 4-2 4-3 4-4 4-4 4-5 4-5 4-5 4-10 4-10 4-10 4-10 4-11 4-14 4-14 4-15 4-17

v

4.5.4 Oracle SYS.ANYTYPE and SYS.ANYDATA Types 4.5.5 The oracle.jdbc Package

4.5.5.1 Interface oracle.jdbc.OracleConnection 4.5.5.2 Interface oracle.jdbc.OracleStatement 4.5.5.3 Interface oracle.jdbc.OraclePreparedStatement 4.5.5.4 Interface oracle.jdbc.OracleCallableStatement 4.5.5.5 Interface oracle.jdbc.OracleResultSet 4.5.5.6 Interface oracle.jdbc.OracleResultSetMetaData 4.5.5.7 Class oracle.jdbc.OracleTypes 4.6 DML Returning 4.6.1 Oracle-Specific APIs 4.6.2 About Running DML Returning Statements 4.6.3 Example of DML Returning 4.6.4 Limitations of DML Returning 4.7 Accessing PL/SQL Associative Arrays

5 Features Specific to JDBC Thin

5.1 Overview of JDBC Thin Client 5.2 Additional Features Supported

5.2.1 Default Support for Native XA 5.2.2 Support for Transaction Guard 5.2.3 Support for Application Continuity

6 Features Specific to JDBC OCI Driver

6.1 OCI Connection Pooling 6.2 Transparent Application Failover 6.3 OCI Native XA 6.4 OCI Instant Client

6.4.1 Overview of Instant Client 6.4.2 OCI Instant Client Shared Libraries 6.4.3 Benefits of Instant Client 6.4.4 JDBC OCI Instant Client Installation Process 6.4.5 Usage of Instant Client 6.4.6 About Patching Instant Client Shared Libraries 6.4.7 Regeneration of Data Shared Library and ZIP files 6.4.8 Database Connection Names for OCI Instant Client 6.4.9 Environment Variables for OCI Instant Client 6.5 About Instant Client Light (English) 6.5.1 Data Shared Library for Instant Client Light (English)

4-18 4-21 4-23 4-23 4-24 4-24 4-25 4-25 4-25 4-27 4-28 4-29 4-29 4-30 4-31

5-1 5-1 5-1 5-2 5-2

6-1 6-1 6-1 6-2 6-2 6-2 6-3 6-3 6-5 6-5 6-6 6-6 6-9 6-9 6-10

vi

6.5.2 6.5.3 6.5.4

Globalization Settings Operation Installing Instant Client Light (English)

6-10 6-11 6-11

7 Server-Side Internal Driver

7.1 Overview of the Server-Side Internal Driver

7-1

7.2 Connecting to the Database

7-1

7.3 About Session and Transaction Context

7-3

7.4 Testing JDBC on the Server

7-4

7.5 Loading an Application into the Server

7-4

7.5.1 Using the Loadjava Utility

7-4

7.5.2 Using the JVM Command Line

7-6

Part III Connection and Security

8 Data Sources and URLs

8.1 About Data Sources 8.1.1 Overview of Oracle Data Source Support for JNDI 8.1.2 Features and Properties of Data Sources 8.1.3 Creating a Data Source Instance and Connecting 8.1.4 Creating a Data Source Instance, Registering with JNDI, and Connecting 8.1.5 Supported Connection Properties 8.1.6 About Using Roles for SYS Login 8.1.7 Configuring Database Remote Login 8.1.8 Using Bequeath Connection and SYS Logon 8.1.9 Setting Properties for Oracle Performance Extensions 8.1.10 Support for Network Data Compression

8.2 Database URLs and Database Specifiers 8.2.1 Support for Internet Protocol Version 6 8.2.2 Support for HTTPS Proxy Configuration 8.2.3 Database Specifiers 8.2.4 Thin-style Service Name Syntax 8.2.5 Support for Delay in Connection Retries 8.2.6 TNSNames Alias Syntax 8.2.7 LDAP Syntax

9 JDBC Client-Side Security Features

9.1 Support for IAM Token-Based Authentication in Oracle Cloud Infrastructure

8-1 8-1 8-2 8-5 8-5 8-7 8-7 8-7 8-9 8-9 8-10 8-11 8-11 8-12 8-12 8-13 8-14 8-14 8-15

9-2

vii

9.2 Support for Oracle Advanced Security 9.2.1 Overview of Oracle Advanced Security 9.2.2 JDBC OCI Driver Support for Oracle Advanced Security 9.2.3 JDBC Thin Driver Support for Oracle Advanced Security

9.3 Support for Login Authentication 9.4 Support for Strong Authentication 9.5 Support for Network Encryption and Integrity

9.5.1 Overview of JDBC Support for Network Encryption and Integrity 9.5.2 JDBC OCI Driver Support for Encryption and Integrity 9.5.3 JDBC Thin Driver Support for Encryption and Integrity 9.5.4 Setting Encryption and Integrity Parameters in Java 9.6 Support for SSL 9.6.1 Overview of JDBC Support for SSL 9.6.2 About Managing Certificates and Wallets 9.6.3 About Keys and certificates containers 9.6.4 Database Connectivity Over TLS Version 1.2 Using JDBC Thin and JKS 9.6.5 Automatic SSL Connection Configuration

9.6.5.1 Provider Resolution 9.6.5.2 Automatic Key Store Type (KSS) Resolution 9.6.6 Support for Default SSL Context 9.6.7 Support for Key Store Service 9.7 Support for Kerberos 9.7.1 Overview of JDBC Support for Kerberos 9.7.2 Configuring Windows to Use Kerberos 9.7.3 Configuring Oracle Database to Use Kerberos 9.7.4 Code Example for Using Kerberos 9.8 Support for RADIUS 9.8.1 Overview of JDBC Support for RADIUS 9.8.2 Configuring Oracle Database to Use RADIUS 9.8.3 Code Example for Using RADIUS 9.9 About Secure External Password Store

10 Proxy Authentication

10.1 About Proxy Authentication 10.2 Types of Proxy Connections 10.3 Creating Proxy Connections 10.4 Closing a Proxy Session 10.5 Caching Proxy Connections 10.6 Limitations of Proxy Connections

9-5 9-5 9-6 9-7 9-8 9-8 9-9 9-9 9-10 9-11 9-12 9-14 9-14 9-16 9-16 9-16 9-17 9-17 9-18 9-19 9-19 9-20 9-20 9-20 9-21 9-22 9-26 9-27 9-27 9-28 9-29

10-1 10-2 10-3 10-5 10-5 10-6

viii

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download