Oracle in a Nutshell

http://www.oreilly.com/catalog/oracleian/?CMP=OT16271

By Rick Greenwald,
David C. Kreines

O’Reilly & Associates, Inc.

December 2002

0-596-00336-6, Order Number: 3366

926 pages

$49.95 US
$77.95 CA
#35.50 UK

Buy this book

The goal of Oracle in a Nutshell is to pull together the most essential information on Oracle architecture, syntax, and user interfaces. The content and format of this book, an admirable addition to O’Reilly’s respected In-a-Nutshell line, combine to boil down vital Oracle commands, language constructs, parameters, and file formats in a succinct and highly accessible desktop reference.

Chapter 11: Java and Oracle

The growth in Java usage and popularity has been a key development in the computing world in recent years. Java’s cross-platform capabilities and object-oriented functionality have given it broad acceptance as a development and runtime platform. Since the introduction of Oracle8i, Java has been an integral part of the overall Oracle environment.

There are two basic ways to access Oracle data from Java:


SQLJ

A high-level language designed for embedding SQL statements into Java code. SQL statements used in SQLJ are checked at compile time. Up until Oracle9i, you could use SQLJ only for static SQL statements. With Oracle9i, you can now use SQLJ for both static and dynamic SQL statements.

JDBC

A Java API that typically involves more coding than SQLJ. The SQL statements used in JDBC code are checked at runtime, so it is more loosely typed than SQLJ.

Both of these interfaces are established standards for Java, and each has its own virtues–fewer statements to code with SQLJ, more control with JDBC. To some extent, use of either interface is a matter of personal choice, although Java, with its low-level programming orientation, tends to appeal to developers who are not deterred by the more detailed coding required with JDBC. You can even mix JDBC calls with SQLJ in the same program if you wish.

This chapter focuses on using Java to interface with Oracle databases. It covers the following:


  • Java drivers available for Oracle
  • Using Java within the Oracle database
  • Mapping between Java datatypes and Oracle datatypes
  • SQLJ and JDBC interfaces to Oracle

The use of Java in general is beyond the scope of this book. However, for a very helpful summary of Java capabilities and syntax, we recommend Java in a Nutshell by David Flanagan (O’Reilly). For additional information about SQLJ and JDBC, see Java Programming with Oracle SQLJ by Jason Price and Java Programming with Oracle JDBC by Don Bales, also from O’Reilly. See also the Oracle documentation for these products.

Java Drivers

Oracle supplies two types of JDBC drivers:


  • A JDBC Oracle Call Interface (OCI) driver, or fat driver, which is a Type 2 driver. This driver allows you to use the full capabilities of Oracle Net Services.
  • A JDBC thin driver, a Type 4 driver that is 100% pure Java but does not provide all the capabilities of Oracle Net Services.

Each of these types of drivers has client-side and server-side versions.

Check the Oracle documentation for your version of Oracle for a compatibility listing for these drivers, the Oracle version number, and the supported versions of the JDK and JDBC code.

Latest Articles