Tài liệu Oracle® Database JDBC Developer’s Guide and Reference pptx

486 2.4K 1
Tài liệu Oracle® Database JDBC Developer’s Guide and Reference pptx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Oracle® Database JDBC Developer’s Guide and Reference 10g Release 2 (10.2) B14355-04 March 2010 This book describes how to use the Oracle JDBC drivers to develop powerful Java database applications. Oracle Database JDBC Developer's Guide and Reference, 10g Release 2 (10.2) B14355-04 Copyright © 1999, 2010, Oracle and/or its affiliates. All rights reserved. Primary Author: Venkatasubramaniam Iyer, Elizabeth Hanes Perry, Brian Wright, Thomas Pfaeffle Contributing Author: Brian Martin Contributor: Kuassi Mensah, Magdi Morsi, Ron Peterson, Ekkehard Rohwedder, Ashok Shivarudraiah, Catherine Wong, Ed Shirk, Tong Zhou, Longxing Deng, Jean de Lavarene, Rosie Chen, Sunil Kunisetty, Joyce Yang, Mehul Bastawala, Luxi Chidambaran, Srinath Krishnaswamy, Rajkumar Irudayaraj, Scott Urman, Jerry Schwarz, Steve Ding, Soulaiman Htite, Douglas Surber, Anthony Lai, Paul Lo, Prabha Krishna, Ellen Siegal, Susan Kraft, Sheryl Maring, Angie Long 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 software or related documentation is delivered to the U.S. Government or anyone licensing it on behalf of the U.S. Government, the following notice is applicable: U.S. GOVERNMENT RIGHTS Programs, software, databases, and related documentation and technical data delivered to U.S. Government customers are "commercial computer software" or "commercial technical data" pursuant to the applicable Federal Acquisition Regulation and agency-specific supplemental regulations. As such, the use, duplication, disclosure, modification, and adaptation shall be subject to the restrictions and license terms set forth in the applicable Government contract, and, to the extent applicable by the terms of the Government contract, the additional rights set forth in FAR 52.227-19, Commercial Computer Software License (December 2007). Oracle USA, Inc., 500 Oracle Parkway, Redwood City, CA 94065. This software 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 which may create a risk of personal injury. If you use this software in dangerous applications, then you shall be responsible to take all appropriate fail-safe, backup, redundancy, and other measures to ensure the safe use of this software. Oracle Corporation and its affiliates disclaim any liability for any damages caused by use of this software in dangerous applications. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. This software and documentation may provide access to or information on 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. 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. iii Contents Preface xix Audience xix Documentation Accessibility xix Related Documents xx Conventions xxii Part I Overview 1 Introducing JDBC Overview of JDBC 1-1 Overview of the Oracle JDBC Drivers 1-1 Common Features of Oracle JDBC Drivers 1-2 JDBC Thin Driver 1-3 JDBC OCI Driver 1-3 JDBC Server-Side Thin Driver 1-3 JDBC Server-Side Internal Driver 1-4 Choosing the Appropriate Driver 1-4 Feature Differences Between JDBC OCI and Thin Drivers 1-5 Overview of Application and Applet Functionality 1-5 Applet Basics 1-5 Oracle Extensions 1-6 Server-Side Basics 1-6 Environments and Support 1-7 Supported JDK and JDBC Versions 1-7 JNI and Java Environments 1-7 JDBC and IDEs 1-7 Changes At This Release 1-7 New Features 1-7 Desupported Features 1-9 Interface Changes 1-9 Feature List 1-10 2 Getting Started Compatibilities for Oracle JDBC Drivers 2-1 Verifying a JDBC Client Installation 2-1 iv Checking Installed Directories and Files 2-2 Checking the Environment Variables 2-3 Ensuring that the Java Code Can Be Compiled and Run 2-4 Determining the Version of the JDBC Driver 2-4 Testing JDBC and the Database Connection 2-5 3 Basic Features Basic Steps in JDBC 3-1 Importing Packages 3-2 Opening a Connection to a Database 3-2 Creating a Statement Object 3-3 Running a Query and Retrieving a ResultSet Object 3-3 Processing the ResultSet Object 3-3 Closing the ResultSet and Statement Objects 3-4 Making Changes to the Database 3-4 Committing Changes 3-5 Closing the Connection 3-5 Sample: Connecting, Querying, and Processing the Results 3-6 Stored Procedure Calls in JDBC Programs 3-6 PL/SQL Stored Procedures 3-6 Java Stored Procedures 3-7 Processing SQL Exceptions 3-7 Part II Oracle JDBC 4 JDBC Standards Support Introduction 4-1 JDBC 2.0 Support: JDK 1.2.x and Later Versions 4-1 Data Type Support 4-2 Standard Feature Support 4-2 Extended Feature Support 4-2 Standard versus Oracle Performance Enhancement APIs 4-2 JDBC 3.0 Support: JDK 1.4 and Previous Releases 4-2 Overview of Supported JDBC 3.0 Features 4-3 Transaction Savepoints 4-3 Creating a Savepoint 4-4 Rolling back to a Savepoint 4-4 Releasing a Savepoint 4-4 Checking Savepoint Support 4-5 Savepoint Notes 4-5 Savepoint Interfaces 4-5 Pre-JDK1.4 Savepoint Support 4-6 Retrieval of Auto-Generated Keys 4-6 java.sql.DatabaseMetaData 4-6 java.sql.Statement 4-6 java.sql.Connection 4-7 v Sample Code 4-7 JDBC 3.0 LOB Interface Methods 4-8 Result Set Holdability 4-8 5 Oracle Extensions Introduction to Oracle Extensions 5-1 Support Features of the Oracle Extensions 5-1 Support for Oracle Data Types 5-2 Support for Oracle Objects 5-2 Support for Schema Naming 5-3 DML Returning 5-4 Accessing PL/SQL Index-by Tables 5-4 Oracle JDBC Packages 5-4 Package oracle.sql 5-4 Package oracle.jdbc 5-10 Oracle Character Data Types Support 5-10 SQL CHAR Data Types 5-10 SQL NCHAR Data Types 5-10 Class oracle.sql.CHAR 5-11 Additional Oracle Type Extensions 5-13 Oracle ROWID Type 5-14 Oracle REF CURSOR Type Category 5-15 Oracle BINARY_FLOAT and BINARY_DOUBLE Types 5-16 The oracle.jdbc Package 5-17 Interface oracle.jdbc.OracleConnection 5-18 Interface oracle.jdbc.OracleStatement 5-19 Interface oracle.jdbc.OraclePreparedStatement 5-20 Interface oracle.jdbc.OracleCallableStatement 5-21 Interface oracle.jdbc.OracleResultSet 5-23 Interface oracle.jdbc.OracleResultSetMetaData 5-24 Class oracle.jdbc.OracleTypes 5-24 Method getJavaSqlConnection 5-25 DML Returning 5-26 Oracle-Specific APIs 5-27 Running DML Returning Statements 5-27 Example of DML Returning 5-28 Limitations of DML Returning 5-29 Accessing PL/SQL Index-by Tables 5-29 Overview 5-29 Binding IN Parameters 5-30 Receiving OUT Parameters 5-31 Type Mappings 5-33 6 Features Specific to JDBC Thin Introduction to JDBC Thin Client 6-1 Additional Features Supported 6-1 vi Support for Applets 6-2 Default Support for Native XA 6-2 JDBC in Applets 6-2 Connecting to the Database through the Applet 6-2 Connecting to a Database on a Different Host Than the Web Server 6-3 Using the Oracle Connection Manager 6-3 Using Signed Applets 6-5 Using Applets with Firewalls 6-6 Configuring a Firewall for Applets that use the JDBC Thin Driver 6-6 Writing a URL to Connect through a Firewall 6-7 Packaging Applets 6-8 Specifying an Applet in an HTML Page 6-8 CODE, HEIGHT, and WIDTH 6-8 CODEBASE 6-9 ARCHIVE 6-9 7 Features Specific to JDBC OCI OCI Connection Pooling 7-1 Transparent Application Failover 7-1 OCI Native XA 7-1 OCI Instant Client 7-1 Overview of Instant Client 7-2 Benefits of Instant Client 7-2 JDBC OCI Instant Client Installation Process 7-3 Usage of Instant Client 7-4 Patching Instant Client Shared Libraries 7-4 Regeneration of Data Shared Library and ZIP files 7-5 Database Connection Names for OCI Instant Client 7-5 Environment Variables for OCI Instant Client 7-7 Instant Client Light (English) 7-8 Globalization Settings 7-9 Operation 7-9 Installation 7-10 8 Server-Side Internal Driver Introduction 8-1 Connecting to the Database 8-1 Exception-Handling Extensions 8-3 Session and Transaction Context 8-4 Testing JDBC on the Server 8-4 Loading an Application into the Server 8-5 Server-Side Character Set Conversion of oracle.sql.CHAR Data 8-6 Part III Connection and Security vii 9 Data Sources and URLs Data Sources 9-1 Overview of Oracle Data Source Support for JNDI 9-1 Features and Properties of Data Sources 9-2 Creating a Data Source Instance and Connecting 9-6 Creating a Data Source Instance, Registering with JNDI, and Connecting 9-6 Supported Connection Properties 9-7 Using Roles for SYS Login 9-9 Configuring Database Remote Login 9-10 Bequeath Connection and SYS Logon 9-11 Properties for Oracle Performance Extensions 9-11 Logging and Tracing 9-12 Database URLs and Database Specifiers 9-13 10 JDBC Client-Side Security Features Support for Oracle Advanced Security 10-1 JDBC OCI Driver Support for Oracle Advanced Security 10-1 JDBC Thin Driver Support for Oracle Advanced Security 10-2 Support for Login Authentication 10-2 Support for Data Encryption and Integrity 10-2 JDBC OCI Driver Support for Encryption and Integrity 10-3 JDBC Thin Driver Support for Encryption and Integrity 10-4 Setting Encryption and Integrity Parameters in Java 10-5 Secure External Password Store 10-7 11 SSL Support Overview of SSL 11-1 Java Version of SSL 11-1 SSL in JDBC 11-2 Non-JSSE Related Properties 11-2 JSSE Related Properties 11-4 Enabling SSL 11-5 12 Proxy Authentication Need for Proxy Authentication 12-1 Creating Proxy Connections 12-2 Caching Proxy Connections 12-3 Part IV Data Access and Manipulation 13 Accessing and Manipulating Oracle Data Data Type Mappings 13-1 Table of Mappings 13-1 Notes Regarding Mappings 13-3 Data Conversion Considerations 13-3 viii Standard Types Versus Oracle Types 13-4 Converting SQL NULL Data 13-4 Testing for NULLs 13-4 Result Set and Statement Extensions 13-5 Comparison of Oracle get and set Methods to Standard JDBC 13-5 Standard getObject Method 13-6 Oracle getOracleObject Method 13-6 Summary of getObject and getOracleObject Return Types 13-7 Other getXXX Methods 13-9 Return Types of getXXX Methods 13-9 Special Notes about getXXX Methods 13-11 Data Types For Returned Objects from getObject and getXXX 13-11 The setObject and setOracleObject Methods 13-12 Other setXXX Methods 13-13 Input Parameter Types of setXXX Methods 13-13 Setter Method Size Limitations 13-15 Setter Methods That Take Additional Input 13-15 Method setFixedCHAR for Binding CHAR Data into WHERE Clauses 13-16 Using Result Set Meta Data Extensions 13-17 14 Java Streams in JDBC Overview 14-1 Streaming LONG or LONG RAW Columns 14-2 LONG RAW Data Conversions 14-2 LONG Data Conversions 14-2 Streaming Example for LONG RAW Data 14-3 Avoiding Streaming for LONG or LONG RAW 14-5 Streaming CHAR, VARCHAR, or RAW Columns 14-5 Streaming LOBs and External Files 14-6 Data Streaming and Multiple Columns 14-7 Closing a Stream 14-8 Notes and Precautions on Streams 14-8 Streaming Data Precautions 14-8 Using Streams to Avoid Limits on setBytes and setString 14-9 Streaming and Row Prefetching 14-9 15 Working with Oracle Object Types Mapping Oracle Objects 15-1 Using the Default STRUCT Class for Oracle Objects 15-2 STRUCT Class Functionality 15-2 Retrieving STRUCT Objects and Attributes 15-3 Creating STRUCT Objects and Descriptors 15-5 Binding STRUCT Objects into Statements 15-7 STRUCT Automatic Attribute Buffering 15-7 Creating and Using Custom Object Classes for Oracle Objects 15-8 Relative Advantages of ORAData versus SQLData 15-9 Understanding Type Maps for SQLData Implementations 15-9 ix Creating Type Map and Defining Mappings for a SQLData Implementation 15-10 Adding Entries to an Existing Type Map 15-10 Creating a New Type Map 15-11 Materializing Object Types not Specified in the Type Map 15-11 Understanding the SQLData Interface 15-12 Reading and Writing Data with a SQLData Implementation 15-13 Understanding the ORAData Interface 15-16 Reading and Writing Data with a ORAData Implementation 15-17 Additional Uses for ORAData 15-20 The Deprecated CustomDatum Interface 15-20 Object-Type Inheritance 15-21 Creating Subtypes 15-21 Implementing Customized Classes for Subtypes 15-22 Use of ORAData for Type Inheritance Hierarchy 15-22 Use of SQLData for Type Inheritance Hierarchy 15-25 JPublisher Utility 15-27 Retrieving Subtype Objects 15-27 Creating Subtype Objects 15-29 Sending Subtype Objects 15-30 Accessing Subtype Data Fields 15-30 Inheritance Meta Data Methods 15-31 Using JPublisher to Create Custom Object Classes 15-32 JPublisher Functionality 15-32 JPublisher Type Mappings 15-33 Describing an Object Type 15-35 Functionality for Getting Object Meta Data 15-35 Steps for Retrieving Object Meta Data 15-36 16 Working with LOBs and BFILEs Oracle Extensions for LOBs and BFILEs 16-1 Working with BLOBs and CLOBs 16-2 Getting and Passing BLOB and CLOB Locators 16-2 Retrieving BLOB and CLOB Locators 16-2 Passing BLOB and CLOB Locators 16-3 Reading and Writing BLOB and CLOB Data 16-4 Creating and Populating a BLOB or CLOB Column 16-7 Accessing and Manipulating BLOB and CLOB Data 16-8 Additional BLOB and CLOB Features 16-9 Data Interface for LOBs 16-12 Working With Temporary LOBs 16-14 Using Open and Close With LOBs 16-16 Working with BFILEs 16-16 Getting and Passing BFILE Locators 16-16 Reading BFILE Data 16-18 Creating and Populating a BFILE Column 16-19 Accessing and Manipulating BFILE Data 16-20 Additional BFILE Features 16-21 x 17 Using Oracle Object References Oracle Extensions for Object References 17-1 Overview of Object Reference Functionality 17-2 Object Reference Getter and Setter Methods 17-2 Key REF Class Methods 17-2 Retrieving and Passing an Object Reference 17-3 Retrieving an Object Reference from a Result Set 17-3 Retrieving an Object Reference from a Callable Statement 17-4 Passing an Object Reference to a Prepared Statement 17-4 Accessing and Updating Object Values through an Object Reference 17-5 Custom Reference Classes with JPublisher 17-5 18 Working with Oracle Collections Oracle Extensions for Collections 18-1 Choices in Materializing Collections 18-1 Creating Collections 18-2 Creating Multilevel Collection Types 18-3 Overview of Collection Functionality 18-3 Array Getter and Setter Methods 18-3 ARRAY Descriptors and ARRAY Class Functionality 18-4 ARRAY Performance Extension Methods 18-5 Accessing oracle.sql.ARRAY Elements as Arrays of Java Primitive Types 18-5 ARRAY Automatic Element Buffering 18-6 ARRAY Automatic Indexing 18-6 Creating and Using Arrays 18-7 Creating ARRAY Objects and Descriptors 18-7 Retrieving an Array and Its Elements 18-10 Retrieving the Array 18-10 Data Retrieval Methods 18-11 Comparing the Data Retrieval Methods 18-12 Retrieving Elements of a Structured Object Array According to a Type Map 18-12 Retrieving a Subset of Array Elements 18-13 Retrieving Array Elements into an oracle.sql.Datum Array 18-13 Accessing Multilevel Collection Elements 18-14 Passing Arrays to Statement Objects 18-15 Using a Type Map to Map Array Elements 18-16 Custom Collection Classes with JPublisher 18-18 19 Result Set Overview 19-1 Result Set Functionality and Result Set Categories Supported in JDBC 2.0 19-1 Oracle JDBC Implementation Overview for Result Set Enhancements 19-3 Creating Scrollable or Updatable Result Sets 19-5 Specifying Result Set Scrollability and Updatability 19-5 Result Set Limitations and Downgrade Rules 19-6 Positioning and Processing in Scrollable Result Sets 19-8 [...]... Oracle Database JDBC Developer's Guide and Reference discussing the intended audience, structure, and conventions of this document A list of related Oracle documents is also provided Audience The Oracle Database JDBC Developer's Guide and Reference is intended for developers of Java Database Connectivity (JDBC) -based applications and applets This book can be read by anyone with an interest in JDBC programming,... Oracle JDBC drivers and the Oracle Database Figure 1–1 Architecture of the Oracle JDBC Drivers and Oracle Database Oracle Database JDBC Thin Driver Java Engine Java Sockets Server-Side Thin Driver JDBC OCI Driver OCI C Library SOL Engine PL/SQL Engine JDBC Server-Side Internal Driver KPRB C Library Oracle Database This section covers the following topics: ■ Common Features of Oracle JDBC Drivers ■ JDBC. .. 1.4.1 All the JDBC drivers support the following standards and features: ■ Same syntax and APIs ■ Same Oracle extensions ■ Full support for multithreaded applications 1-2 Oracle Database JDBC Developer's Guide and Reference Overview of the Oracle JDBC Drivers Oracle JDBC drivers implement the standard java.sql interfaces You can access the Oracle-specific features, in addition to the standard features,... following topics: ■ Supported JDK and JDBC Versions ■ JNI and Java Environments ■ JDBC and IDEs Supported JDK and JDBC Versions In Oracle Database 10g release 2 (10.2), all the JDBC drivers are compatible with JDK 1.2.x and later JDK 1.0.x and JDK 1.1.x are no longer supported, and therefore, the classes111.zip, classes111.jar, classes111_g.zip, classes111_g.jar, and nls_charset11.zip files are no... implementation of Java Database Connectivity (JDBC) , covering the following topics: ■ Overview of JDBC ■ Overview of the Oracle JDBC Drivers ■ Overview of Application and Applet Functionality ■ Server-Side Basics ■ Environments and Support ■ Changes At This Release Overview of JDBC JDBC is a Java standard that provides the interface for connecting from Java to relational databases The JDBC standard is defined... See Also: "Session and Transaction Context" on page 8-4 1-6 Oracle Database JDBC Developer's Guide and Reference Changes At This Release Connecting to the Database The JDBC server-side internal driver uses a default connection to the database You connect to the database with the OracleDataSource.getconnection method See Also: "Connecting to the Database" on page 8-1 Environments and Support This section... JavaBeans Developer's Guide This book provides information about the EJB implementation and EJB container in OC4J The following documents are from the Oracle Server Technologies group: ■ Oracle Database Advanced Application Developer's Guide ■ Oracle Database PL/SQL Packages and Types Reference ■ Oracle Database PL/SQL Language Reference ■ Oracle Database SQL Language Reference ■ Oracle Database Net Services... standard is defined by Sun Microsystems and implemented through the standard java.sql interfaces This allows individual providers to implement and extend the standard with their own JDBC drivers JDBC is based on the X/Open SQL Call Level Interface (CLI) JDBC 4.0 complies with the SQL 2003 standard Overview of the Oracle JDBC Drivers In addition to supporting the standard JDBC application programming interfaces... Layer (SSL), 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 If you are writing an applet, then you must use the JDBC Thin driver 1-4 Oracle Database JDBC Developer's Guide and Reference Overview of Application and Applet Functionality ■... internal to the JDBC OCI driver and are not applicable to the JDBC Thin driver Most JDBC OCI driver features are not available in the JDBC Thin driver because they are inherited from OCI See Also: ■ Chapter 6, "Features Specific to JDBC Thin" ■ Chapter 7, "Features Specific to JDBC OCI" Overview of Application and Applet Functionality This section compares and contrasts the basic functionality of JDBC applications . Oracle® Database JDBC Developer’s Guide and Reference 10g Release 2 (10.2) B14355-04 March 2010 This book describes how to use the Oracle JDBC drivers. provided. Audience The Oracle Database JDBC Developer's Guide and Reference is intended for developers of Java Database Connectivity (JDBC) -based applications and applets.

Ngày đăng: 20/02/2014, 05:21

Từ khóa liên quan

Mục lục

  • Contents

  • List of Tables

  • Preface

    • Audience

    • Documentation Accessibility

    • Related Documents

    • Conventions

    • Part I Overview

      • 1 Introducing JDBC

        • Overview of JDBC

        • Overview of the Oracle JDBC Drivers

          • Common Features of Oracle JDBC Drivers

          • JDBC Thin Driver

          • JDBC OCI Driver

          • JDBC Server-Side Thin Driver

          • JDBC Server-Side Internal Driver

          • Choosing the Appropriate Driver

          • Feature Differences Between JDBC OCI and Thin Drivers

          • Overview of Application and Applet Functionality

            • Applet Basics

            • Oracle Extensions

            • Server-Side Basics

            • Environments and Support

              • Supported JDK and JDBC Versions

              • JNI and Java Environments

              • JDBC and IDEs

Tài liệu cùng người dùng

Tài liệu liên quan