Oracle - Oracle Database Java Developers Guide, 11g Release.pdf

(6062 KB) Pobierz
Oracle® Database
Java Developer’s Guide,
11g Release 2 (11.2)
E10588-03
December 2009
This book describes how to develop, load, and run Java
applications in Oracle Database.
Oracle Database Java Developer's Guide, 11g Release 2 (11.2)
E10588-03
Copyright © 1999, 2009, Oracle and/or its affiliates. All rights reserved.
Primary Author:
Tulika Das, Sheryl Maring, Rick Sapir, Michael Wiesenberg
Venkatasubramaniam Iyer, Brian Wright, Timothy Smith
Contributing Author:
Contributor: Malik Kalfane, Kuassi Mensah, Mark Jungerman, Suresh Srinivasan, Ernest Tucker, Robert H
Lee, Dmitry Nizhegorodov, David Unietis, Paul Lo, Steve Harris, Ellen Barnes, Peter Benson, Greg Colvin,
Bill Courington, Matthieu Devin, Jim Haungs, Hal Hildebrand, Susan Kraft, Thomas Kurian, Scott Meyer,
Tom Portfolio, Dave Rosenberg, Jerry Schwarz, Harlan Sexton, Xuhua Li
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.
Contents
Preface
...............................................................................................................................................................
xv
Audience.....................................................................................................................................................
Documentation Accessibility ...................................................................................................................
Related Documents ...................................................................................................................................
Conventions ...............................................................................................................................................
xv
xv
xvi
xvi
1
Introduction to Java in Oracle Database
Overview of Java
......................................................................................................................................
1-1
Java and Object-Oriented Programming Terminology ................................................................
1-2
Classes ..........................................................................................................................................
1-2
Objects ..........................................................................................................................................
1-2
Interfaces ......................................................................................................................................
1-3
Encapsulation ..............................................................................................................................
1-3
Inheritance ...................................................................................................................................
1-3
Polymorphism .............................................................................................................................
1-4
Key Features of the Java Language .................................................................................................
1-5
JVM......................................................................................................................................................
1-6
Java Class Hierarchy..........................................................................................................................
1-7
Using Java in Oracle Database...............................................................................................................
1-8
Java and RDBMS: A Robust Combination .....................................................................................
1-8
Multithreading....................................................................................................................................
1-9
Memory Spaces Management .......................................................................................................
1-10
Footprint ...........................................................................................................................................
1-11
Performance of Oracle JVM ...........................................................................................................
1-12
Dynamic Class Loading .................................................................................................................
1-13
Overview of Oracle JVM
.....................................................................................................................
1-14
Process Area.....................................................................................................................................
1-15
The main() Method .........................................................................................................................
1-15
The GUI ............................................................................................................................................
1-15
The IDE .............................................................................................................................................
1-15
New Features in This Release.............................................................................................................
1-15
Internet Protocol Version 6 Support.............................................................................................
1-16
Feature List of Oracle JVM
..................................................................................................................
1-16
Main Components of Oracle JVM
.....................................................................................................
1-17
Library Manager..............................................................................................................................
1-18
iii
Compiler...........................................................................................................................................
Interpreter.........................................................................................................................................
Class Loader.....................................................................................................................................
Verifier ..............................................................................................................................................
Server-Side JDBC Internal Driver .................................................................................................
Server-Side SQLJ Translator ..........................................................................................................
System Classes .................................................................................................................................
Java Application Strategy of Oracle
..................................................................................................
Java in Database Application Development ...............................................................................
Java Programming Environment ..................................................................................................
Java Stored Procedures...................................................................................................................
PL/SQL Integration and Oracle RDBMS Functionality ............................................................
JDBC Drivers ............................................................................................................................
SQLJ ...........................................................................................................................................
JPublisher ..................................................................................................................................
Development Tools .........................................................................................................................
Memory Model for Dedicated Mode Sessions................................................................................
1-18
1-18
1-18
1-18
1-19
1-19
1-19
1-19
1-20
1-20
1-20
1-21
1-21
1-21
1-22
1-22
1-22
2
Java Applications on Oracle Database
Database Sessions Imposed on Java Applications
............................................................................
2-1
Execution Control of Java Applications...............................................................................................
2-3
Java Code, Binaries, and Resources Storage
.......................................................................................
2-3
Preparing Java Class Methods for Execution......................................................................................
2-5
Compiling Java Classes .....................................................................................................................
2-5
Compiling Source Through javac .............................................................................................
2-6
Compiling Source Through the loadjava Tool .......................................................................
2-6
Compiling Source at Run Time.................................................................................................
2-6
Specifying Compiler Options....................................................................................................
2-6
Recompiling Automatically.......................................................................................................
2-8
Resolving Class Dependencies.........................................................................................................
2-9
Loading Classes ...............................................................................................................................
2-12
Granting Execute Rights ................................................................................................................
2-15
Controlling the Current User ........................................................................................................
2-16
Checking Java Uploads ..................................................................................................................
2-18
Publishing.........................................................................................................................................
2-19
Auditing............................................................................................................................................
2-19
User Interfaces on the Server
..............................................................................................................
2-20
Shortened Class Names........................................................................................................................
2-21
Class.forName() in Oracle Database..................................................................................................
2-22
Supply ClassLoader in Class.forName()......................................................................................
2-23
Supply Class and Schema Names to classForNameAndSchema() ..........................................
2-24
Supply Class and Schema Names to lookupClass()...................................................................
2-24
Supply Class and Schema Names when Serializing ..................................................................
2-24
Class.forName Example.................................................................................................................
2-25
Managing Your Operating System Resources
.................................................................................
2-26
Overview of Operating System Resources ..................................................................................
2-26
Garbage Collection and Operating System Resources ..............................................................
2-27
iv
Managing Your Applications Using JMX
.........................................................................................
Overview of JMX.............................................................................................................................
Enabling and Starting JMX in a Session.......................................................................................
OJVM JMX Defaults and Configurability....................................................................................
Examples of SQL calls to dbms_java.start_jmx_agent...............................................................
Using JConsole to Monitor and Control Oracle JVM.................................................................
The jconsole Command...........................................................................................................
The JConsole interface.............................................................................................................
The OracleRuntime MBean ....................................................................................................
Memory Thresholds ................................................................................................................
Important Security Notes...............................................................................................................
Threading in Oracle Database
............................................................................................................
Shared Servers Considerations...........................................................................................................
End-of-Call Migration ....................................................................................................................
Oracle-Specific Support for End-of-Call Optimization .............................................................
The EndOfCallRegistry.registerCallback() Method ...................................................................
The EndOfCallRegistry.runCallbacks() Method ........................................................................
The Callback Interface ....................................................................................................................
The Callback.act() method .............................................................................................................
Operating System Resources Affected Across Calls ..................................................................
2-28
2-28
2-29
2-30
2-31
2-32
2-32
2-32
2-42
2-44
2-46
2-46
2-49
2-49
2-50
2-53
2-53
2-54
2-54
2-54
3
Calling Java Methods in Oracle Database
Invoking Java Methods
...........................................................................................................................
3-1
Using PL/SQL Wrappers..................................................................................................................
3-1
JNI Support .........................................................................................................................................
3-3
Utilizing SQLJ and JDBC with Java in the Database.....................................................................
3-3
JDBC..............................................................................................................................................
3-4
SQLJ ..............................................................................................................................................
3-4
Example Comparing JDBC and SQLJ ......................................................................................
3-5
Complete SQLJ Example............................................................................................................
3-6
SQLJ Strong Typing Paradigm..................................................................................................
3-7
Translating a SQLJ Program......................................................................................................
3-7
Running a SQLJ Program in the Server ...................................................................................
3-8
Converting a Client Application to Run on the Server .........................................................
3-8
Interacting with PL/SQL ...........................................................................................................
3-8
Using Command-Line Interface.......................................................................................................
3-9
Using the Client-Side Stub .............................................................................................................
3-10
Debugging Server Applications.........................................................................................................
3-13
How To Tell You Are Running on the Server
..................................................................................
3-13
Redirecting Output on the Server
......................................................................................................
3-14
Calling Java in the Database Directly
...............................................................................................
3-20
4
Java Installation and Configuration
Initializing a Java-Enabled Database
...................................................................................................
4-1
Configuring with Oracle Database Template ................................................................................
4-1
Modifying an Existing Oracle Database to Include Oracle JVM.................................................
4-1
v
Zgłoś jeśli naruszono regulamin