# CHAPTER 1: Overview

## 1.1 What is JDBC?

JDBC is a JavaTM API for executing SQL statements. It consists of a set of classes and interfaces written in the Java programming language that makes it easy to send SQL statements to virtually any relational database. One can write a single program using the JDBC API, and the program will be able to send SQL statements to the appropriate database. And, with a program written in the Java programming language, one also doesn't have to worry about writing different programs to run on different platforms. The combination of Java and JDBC lets a programmer write the program once and able to execute it anywhere.

Java, being robust, secure, easy to use, easy to understand, and automatically down loadable on a network, is an excellent language basis for database applications. What is needed is a way for Java applications to talk to a variety of different databases. JDBC is the mechanism for doing this.

JDBC extends what you can do in Java. For example, with Java and the JDBC API, it is possible to publish a web page containing an applet that uses information obtained from a remote database. Or an enterprise can use JDBC to connect all its employees (even if they are using a conglomeration of Windows, Macintosh, and UNIX machines) to one or more internal databases via an intranet. With more and more programmers using the Java programming language, the need for easy database access from Java is continuing to grow.

MIS managers like the combination of Java and JDBC because it makes disseminating information easy and economical. Businesses can continue to use their installed databases and access information easily even if it is stored on different database management systems. Development time for new applications is short. Installation and version control are greatly simplified. A programmer can write an application or an update once, put it on the server, and everybody can access to the latest version. And for businesses selling information services, Java and JDBC offer a better way of getting out information updates to external customers.

In summary, the JDBC API is a natural Java interface to the basic SQL abstractions and concepts. It builds on ODBC so programmers familiar with ODBC will find it very easy to learn. JDBC retains the basic design features of ODBC; in fact, both interfaces are based on the X/Open SQL CLI (Call Level Interface). The difference is that JDBC builds on and reinforces the style and virtues of Java, and, of course, it is easy to use.

## 1.2 Java to Empress Framework

Empress JDBC Interface contains both a category 2, and a category 4 JDBC driver. JDBC driver categories/types and the general usage of a JDBC driver are defined by the JDBC API Specification and will not be further documented here.

This document explains the specifics of Empress drivers, and the architecture of the Empress JDBC scenarios.

The basic scenarios are shown below:

  Figure 1-1: Empress JDBC Scenarios

Category 2 and Category 4 Drivers are both used in the two tier system directly accessing the Empress Connectivity Server. Category 4 Driver is a pure java implementation and does not require any shared libaries whereas Category 2 Driver does.

## 1.3 Category 2 JDBC Driver

The category 2 driver can be used with HTTP Servlets, or Java applications running in different Intranet/network environments. Since it is implemented partly in C language a different driver is needed for different platforms.

It is used in two tiers:

- Java application/servlet and the `empress.jdbc.empressDriver`.

  `empress.jdbc.empressDriver` is a mixed Java/C interface that is platform dependent.

- The Empress Connectivity Server.

Writing a Java application or servlet that uses the Empress JDBC driver requires only two Empress specific Java methods:

1. Load the Empress JDBC Driver:

   `Class.forName` ("`empress.jdbc.empressDriver`")

2. Connect to an Empress Connectivity Server:

   `DriverManager.getConnection` ("`jdbc:empress:SERVER=Connectivity_Server_Name;PORT=Connectivity_Server_Port; DATABASE=Empress_Database", uid, pwd`)

## 1.4 Category 2 JDBC "Local Access" Driver

A scenario that utilizes a Category 2 JDBC "Local Access" Driver is a single-tier system. If the client Java application can access the database locally, there is no need for the Empress Connectivity Server. In this case a special Empress JDBC Driver called Empress Category 2 JDBC "Local Access" Driver can be used. This scenario reduces the network overhead and improves the access performance.

Setting a Java application or a servlet that uses an Empress Category 2 JDBC "Local Access" Driver is the same as setting a Java application for an Empress Category 2 JDBC Driver, with a single change:

- Change the Empress JDBC Driver to be loaded:

        Class.forName ("empress.jdbc.empressLocalDriver")

Empress JDBC "Local Access" Driver allows user applications to have simultaneous multiple connections, but not to have transactions in those simultaneous sessions. In another words, user can perform multiple "Connect-Disconnect" sequences, but cannot have transactions in each of those sessions at the same time. User can perform basic Data Manipulation Language (DML) commands, such as delete, update, insert or select, in non-transaction mode in simultaneous sessions. Furthermore, user can perform multiple transactions in non-concurrent sessions.

Another way to overcome the above restriction is to run multiple JDBC "Local Access" applications simultaneously , each having one connection at the time.

It also should be noted that JDBC "Local Access" supports Callable Statements.

## 1.5 Category 4 JDBC Driver

The usage of the Category 4 Driver is preferred over the usage of the Category 2 Driver. The Category 4 Driver can be used with Applets inside HTML browsers, and is more suited to be used in heterogeneous computer environments.

A scenario that utilizes a Category 4 Driver is a two-toer system. The two tiers are:

- Pure Java client containing the Java application/applet and the `com.empress.jdbc4.empressDriver` JDBC client driver.
- The Empress Connectivity server.

Your application/applet is part of the same process space as the pure Java client and is therefore platform independent. This means that your application can run on any O/S that has a Java Virtual Machine (JVM), whereas your applets can run inside any browser that is conformant to the Javasoft specification for JVM.

Running an application using the category 4 driver is the same as for category two. And an application written for category two can be used with the category 4 driver with only two changes in code.

1. Change which Empress JDBC driver is loaded by changing:

          Class.forName ("empress.jdbc.empressDriver");

   to:

          Class.forName ("com.empress.jdbc4.empressDriver");

2. Change the CLASSPATH path variable to include:

       	$EMPRESSPATH/jdbc/classes_cat4/empressJDBC_cat4.jar

When you run an Applet the Java Applet is first loaded into an Internet/Intranet browser, or an Applet Viewer, and then a connection is set with the Connectivity Server.

A typical communications protocol is shown below. Note that the HTTP server is optional - the browser could also load the HTML page using the `file://` protocol).

  Figure 1-2: Empress JDBC Interface Communication Protocol