Java Language Integration

Java programmers can write server-side classes that invoke SQL and PL/SQL using standard JDBC or SQLJ calls. PL/SQL programmers can call server-side Java methods by writing a PL/SQL cover or call spec for Java using Oracle database DDL.

Server-side Java in the database may be faster than PL/SQL for computer-intensive programs, but not as nimble for database access. PL/SQL is much more efficient for database-intensive routines because, unlike Java, it doesn’t have to pay the overhead for converting SQL datatypes for use inside the stored program. Database programmers will want to continue to use PL/SQL for programs that perform a lot of database I/O and use Java for the best raw computation performance. Follow these steps to create a Java stored procedure ( JSP):

  1. Write or otherwise obtain functional Java code. Having source code is not necessary, though, so you can use class libraries from third parties. The classes must, however, meet two requirements. Methods published to SQL and PL/SQL must be declared static; PL/SQL has no mechanism for instantiating nonstatic Java classes. In addition, the classes must not issue any GUI calls (for example, to AWT) at runtime.

    If you write your own JSP and it needs to connect to the database for access to tables or stored procedures, use standard JDBC and/or SQLJ calls in your code. Many JDBC and SQLJ reference materials are available to provide assistance in calling SQL or PL/SQL from Java, but be sure to review the product-specific ...

Get Oracle PL/SQL Language Pocket Reference, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.