Oracle8i Java Stored Procedures Developer's Guide Release 2 (8.1.6) Part Number A81358-01 |
Library | Service | Contents | Index

#
Preface

Welcome to the future of database programming. The rapid rise of Java has forever changed the art of software development. Now, using intranets, the Internet, and Java's cross-platform ability, you can develop applications with global reach. The Oracle JServer and its Java virtual machine (JVM) provide an ideal platform on which to deploy such applications.

This guide gets you started building Java applications for Oracle8i. Working from simple examples, you quickly learn how to load, publish, and call Java stored procedures.

#### Major Topics

- Who Should Read This Guide?

- How This Guide Is Organized

- Notational Conventions

- Sample Database Tables

- Related Publications

- Suggested Reading

## Who Should Read This Guide?

Anyone developing Java applications for Oracle8i will benefit from reading this guide. Written especially for programmers, it will also be of value to architects, systems analysts, project managers, and others interested in network-centric database applications. To use this guide effectively, you must have a working knowledge of Java, SQL, PL/SQL, and Oracle8i.

Note: This guide presumes you are an experienced Java programmer. If you are just learning Java, see "Suggested Reading".

## How This Guide Is Organized

This guide is divided into the following five chapters:

##### Chapter 1, "Introduction"

After discussing Java's synergy with the Oracle RDBMS, this chapter surveys the main features of stored procedures and points out the advantages they offer. Then, you learn how the JServer JVM and its main components work with Oracle8i. The chapter ends with an overview of the Java stored procedures development process.

##### Chapter 2, "Loading Java Classes"

This chapter shows you how to load Java source, class, and resource files into the Oracle database. You learn how to manage Java schema objects using the `loadjava` and `dropjava` utilities. In addition, you learn about name resolution and invoker rights versus definer rights.

##### Chapter 3, "Publishing Java Classes"

This chapter shows you how to publish Java classes to SQL. Among other things, you learn how to write call specifications, map datatypes, and set parameter modes.

##### Chapter 4, "Calling Stored Procedures"

This chapter shows you how to call Java stored procedures in various contexts. For example, you learn how to call Java from SQL DML statements, database triggers, and PL/SQL blocks.

##### Chapter 5, "Developing an Application"

This chapter ties together what you have learned. Step by step, it walks you through the development of a Java stored procedures application.

## Notational Conventions

This guide follows these conventions:

Convention | Meaning
Italic | Italic font denotes terms being defined for the first time, words being emphasized, error messages, and book titles.
`Courier` | Courier font denotes program code, schema object names, file names, path names, and Internet addresses.

Java code examples follow these conventions:

Convention | Meaning
`{ }` | Braces enclose a block of statements.
`//` | A double slash begins a single-line comment, which extends to the end of a line.
`/* */` | A slash-asterisk and an asterisk-slash delimit a multi-line comment, which can span multiple lines.
`...` | An ellipsis shows that statements or clauses irrelevant to the discussion were left out.
`lower case` | We use lower case for keywords and for one-word names of variables, methods, and packages.
`UPPER CASE` | We use upper case for names of constants (static final variables) and for names of supplied classes that map to built-in SQL datatypes.
`Mixed Case` | We use mixed case for names of classes and interfaces and for multi-word names of variables, methods, and packages. The names of classes and interfaces begin with an upper-case letter. In all multi-word names, the second and succeeding words begin with an upper-case letter.

PL/SQL code examples follow these conventions:

Convention | Meaning
`--` | A double hyphen begins a single-line comment, which extends to the end of a line.
`/* */` | A slash-asterisk and an asterisk-slash delimit a multi-line comment, which can span multiple lines.
`...` | An ellipsis shows that statements or clauses irrelevant to the discussion were left out.
`lower case` | We use lower case for names of constants, variables, cursors, exceptions, subprograms, and packages.
`UPPER CASE` | We use upper case for keywords, names of predefined exceptions, and names of supplied PL/SQL packages.
`Mixed Case` | We use mixed case for names of user-defined datatypes and subtypes. The names of user-defined types begin with an upper-case letter.

Syntax definitions use a simple variant of Backus-Naur Form (BNF) that includes the following symbols:

Symbol | Meaning
`[ ]` | Brackets enclose optional items.
`{ }` | Braces enclose items of which only one is required.
`|` | A vertical bar separates alternatives within brackets or braces.
`...` | An ellipsis shows that the preceding syntactic element can be repeated.
`delimiters` | Delimiters other than brackets, braces, vertical bars, and ellipses must be entered as shown.

## Sample Database Tables

Most programming examples in this guide use two sample database tables named `dept` and `emp`. Their definitions follow:

    CREATE TABLE dept (deptno NUMBER(2) NOT NULL,
                       dname  VARCHAR2(14),
                       loc    VARCHAR2(13));

    CREATE TABLE emp (empno    NUMBER(4) NOT NULL,
                      ename    VARCHAR2(10),
                      job      VARCHAR2(9),
                      mgr      NUMBER(4),
                      hiredate DATE,
                      sal      NUMBER(7,2),
                      comm     NUMBER(7,2),
                      deptno   NUMBER(2));

Respectively, the `dept` and `emp` tables contain the following rows of data:

    DEPTNO  DNAME      LOC
    ------- ---------- ---------
    10      ACCOUNTING NEW YORK
    20      RESEARCH   DALLAS
    30      SALES      CHICAGO
    40      OPERATIONS BOSTON

    EMPNO ENAME   JOB          MGR  HIREDATE    SAL   COMM  DEPTNO
    ----- ------- --------- ------ --------- ------ ------ -------
     7369 SMITH   CLERK       7902 17-DEC-80    800             20
     7499 ALLEN   SALESMAN    7698 20-FEB-81   1600    300      30
     7521 WARD    SALESMAN    7698 22-FEB-81   1250    500      30
     7566 JONES   MANAGER     7839 02-APR-81   2975             20
     7654 MARTIN  SALESMAN    7698 28-SEP-81   1250   1400      30
     7698 BLAKE   MANAGER     7839 01-MAY-81   2850             30
     7782 CLARK   MANAGER     7839 09-JUN-81   2450             10
     7788 SCOTT   ANALYST     7566 19-APR-87   3000             20
     7839 KING    PRESIDENT        17-NOV-81   5000             10
     7844 TURNER  SALESMAN    7698 08-SEP-81   1500      0      30
     7876 ADAMS   CLERK       7788 23-MAY-87   1100             20
     7900 JAMES   CLERK       7698 03-DEC-81    950             30
     7902 FORD    ANALYST     7566 03-DEC-81   3000             20
     7934 MILLER  CLERK       7782 23-JAN-82   1300             10

To create and load the tables, run the script `demobld.sql`, which can be found in the SQL*Plus demo directory.

## Related Publications

Occasionally, this guide refers you to the following Oracle publications for more information:

  Oracle8i Application Developer's Guide - Fundamentals
  Oracle8i Java Developer's Guide
  Oracle8i JDBC Developer's Guide and Reference
  Oracle8i Reference
  Oracle8i SQLJ Developer's Guide and Reference
  Oracle8i SQL Reference
  PL/SQL User's Guide and Reference
  SQL*Plus User's Guide and Reference

## Suggested Reading

The Java Programming Language by Arnold & Gosling, Addison-Wesley, 1998
Coauthored by the originator of Java, this definitive book explains the basic concepts, areas of applicability, and design philosophy of the language. Using numerous examples, it progresses systematically from basic to advanced programming techniques.

Thinking in Java by Bruce Eckel, Prentice Hall, 1998
This book offers a complete introduction to Java on a level appropriate for both beginners and experts. Using simple examples, it presents the fundamentals and complexities of Java in a straightforward, good-humored way.

Core Java by Cornell & Horstmann, Prentice-Hall, 1996
This book is a complete, step-by-step introduction to Java programming principles and techniques. Using real-world examples, it highlights alternative approaches to program design and offers many programming tips and tricks.

Java in a Nutshell by Flanagan, O'Reilly, 1997
This indispensable quick reference provides a wealth of information about Java's most commonly used features. It includes programming tips and traps, excellent examples of problem solving, and tutorials on important features.

Java Software Solutions by Lewis & Loftus, Addison-Wesley, 1998
This book provides a clear, thorough introduction to Java and object-oriented programming. It contains extensive reference material and excellent pedagogy including self-assessment questions, programming projects, and exercises that encourage experimentation.

### Online Sources

There are many useful online sources of information about Java. For example, you can view or download guides and tutorials from the Sun Microsystems home page on the Web:

    http://www.sun.com

Another popular Java Web site is:

    http://www.gamelan.com

For Java API documentation, visit:

    http://www.javasoft.com/products

Also, the following Internet news groups are dedicated to Java:

    comp.lang.java.programmer
    comp.lang.java.misc

At the following site, you can get the latest JServer news, updates, and offerings:

    http://www.oracle.com/java

In addition to try-and-buy tools, you can download JDBC drivers, SQLJ reference implementations, white papers on Java application development, and collections of frequently asked questions (FAQs).

| Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
Library | Service | Contents | Index