Lemur zaprasza
[Chapter 9] Calling Java from PL/SQLChapter 9 9. Calling Java from PL/SQLContents:Oracle8i and JavaGetting Ready to Use Java in OracleA Simple DemonstrationUsing loadjavaUsing dropjavaManaging Java in the DatabaseUsing DBMS_JAVA and DBMS_JAVA_TESTPublishing and Using Java in PL/SQLExamplesIn this chapter, I explore the exciting new feature of Oracle8i that allows a developer to call Java stored procedures (JSPs) from within PL/SQL. Java is a very powerful language, much more robust in many ways than PL/SQL. Java also offers hundreds of classes that provide clean, easy-to-use application programming interface (APIs) to a wide variety of functionality.9.1 Oracle8i and JavaIn Oracle8i, Oracle includes a new product called JServer, which consists of the following elements:Oracle's Java Virtual Machine (JVM), called Aurora, the supporting runtime environment, and Java class libraries Tight integration with PL/SQL and Oracle RDBMS functionality An Object Request Broker (the Aurora/ORB) and Enterprise JavaBeans (EJB) The JServer Accelerator (native compiler) (available in the 8.1.6 Enterprise Edition only)The Aurora JVM executes Java methods (also known as Java stored procedures) and classes if they were stored in the database itself. Java in the Oracle database is a big topic; Java programming all by itself is an even bigger topic. Complete treatment of either is outside the scope of this book. My objectives for this chapter are limited to the following:Providing the information you need to load Java classes into the Oracle database, manage those new database objects, and publish them for use inside PL/SQLOffering a basic tutorial in building Java classes that should give you enough guidance to let you construct simple classes to access underlying Java functionalityTo access Java class methods from within Oracle, you must take the following steps:Create the Java code elements. You can do this in Oracle's JDeveloper, or in any other Java Integrated Development Environment. (notepad.exe will also, of course, do the trick in a pinch!)Load the Java class(es) into Oracle using the loadjava command-line utility or the CREATE JAVA statement.Publish the Java class methods inside PL/SQL by writing wrapper programs in PL/SQL around the Java code.Grant privileges as required on the PL/SQL wrapper programs and the Java class referenced by the PL/SQL wrapper.Call the PL/SQL programs from any one of a number of environments, as illustrated in Figure 9.1.Oracle8i offers a variety of components and commands to work with Java. Table 9.1 summarizes these different elements.Table 9.1: Oracle8i Components and Commands for Java ComponentDescriptionAurora JVMThe Java Virtual Machine (JVM) that Oracle implemented in its database serverloadjavaAn operating system command-line utility that loads your Java code elements (classes, .jar files, etc.) into the Oracle databasedropjavaAn operating system command-line utility that drops your Java code elements (classes, .jar files, etc.) from the Oracle databaseCREATE JAVADROP JAVAALTER JAVANew DDL statements that perform some of the same tasks as loadjava and dropjavaDBMS_JAVAA built-in package that offers a number of utilities to set options and other aspects of the JVMDBMS_JAVA_TESTA built-in package you can use to more easily test your JSPsJPublisherA utility used to build Java classes around object types and REFs defined in the Oracle databaseFigure 9.1: Accessing JSPs from within the Oracle databaseThe remainder of this chapter explains the steps outlined earlier and the components in Table 9.1. For more thorough coverage of Java in the Oracle database, please consult the Oracle documentation.8.5 A Complete FGAC Example9.2 Getting Ready to Use Java in Oracle O'Reilly & Associates. All rights reserved. |