Setting Up Your Environment to Develop SQLJ Programsby Jason Price, author of Java Programming with Oracle SQLJ
SQLJ is a technology that enables a Java program to access a database using embedded Structured Query Language (SQL) statements. You can embed SQLJ statements in many types of Java programs, including stand-alone applications, servlets, JavaServer Pages, and Enterprise JavaBeans. This first column in my Learning SQLJ series introduces SQLJ, describes the software requirements for using it, and shows you how to configure your computer to develop SQLJ programs. I'll also demonstrate how to use SQLJ to develop a version of the classic "Hello World" program that will access a database.
I'm the author of O'Reilly's Java Programming with Oracle SQLJ, which shows you how to get the most out of this powerful technology. These columns will reference numerous SQL scripts, source code, and other files, which are all available for download from the book's O'Reilly Web site. All of the files are contained in a single ZIP file, named
SQLJ_examples.zip, which you should download and then open using WinZip. To extract the ZIP file, you must use the Extract function from the Actions menu, which will create three subdirectories:
programs (contains the program source files),
sql (contains the SQL*Plus scripts to create the database schemas), and
sample_files (contains two sample files).
Requirements for Using SQLJ
SQLJ consists of two components: the translator and the runtime libraries. The translator reads a Java source file containing embedded SQL statements, which are then translated into calls to the SQLJ runtime libraries. The SQLJ translator also compiles the Java source file into byte codes. The calls to the runtime libraries in the compiled code perform the actual database operations. SQLJ is an ISO and ANSI standard that was developed by many large corporations including Oracle, Sun Microsystems, IBM, Compaq, Informix, and Sybase. You can view the latest developments on the SQLJ standard at the SQLJ.org Web site.
There are various software requirements for using SQLJ. Before you can write and execute a SQLJ 8i (or above) program, you need to have the following software installed:
- Oracle SQLJ translator
- Oracle JDBC drivers
- A version of the Sun Microsystems Java Development Kit (JDK)
- An Oracle database, version 8i or above, running the JServer option (JServer is also known as the Oracle JVM)
- Oracle Net8 or above
The SQLJ translator, JDBC drivers, and the JDK need to be installed on the machine that you are using for development. The Oracle8i database and Net8 can reside anywhere on your network, so long as you have access to them. You can download trial versions of all the Oracle software from Oracle's Technet Web site, and you can download the JDK from Sun's Java Web site. If you are installing the Oracle database onto your development machine, you can also choose to install the SQLJ translator and JDBC drivers at the same time. You don't have to install them separately.
The specific version numbers for the above components are important. A given release of SQLJ will only work with specific versions of the JDK and the other Oracle software components. Thus, you not only need to have the right components, but you need to have the right combination of versions. SQLJ versions 8.1.6 and 8.1.7 are compatible with JDK versions 1.1.x and 1.2.x; SQLJ 9i is also compatible with versions of the JDK higher than 1.2.x. JDK version 1.2.2 was used for this article. You should consult the Oracle SQLJ Release Notes for details on which version of the JDK and the other Oracle software components you need if you are using a different version of SQLJ.
All of the examples in this article were developed using Oracle SQLJ version 8.1.6, along with version 8.1.6 of the Oracle JDBC drivers.
In addition to the necessary components listed here, the Oracle JDeveloper tool is very useful when developing Java programs. JDeveloper runs on Windows NT and is a tool that features an integrated development environment. However, JDeveloper is not required in order for you to use SQLJ, because you can use the Oracle Java command-line tools to perform your development tasks. The various Oracle Java command-line utilities use the same syntax and options, regardless of the operating system on which they run.
Configuring Your Environment
This section describes how to configure your the computing environment to develop and run SQLJ programs. Three environment variables must be set:
ORACLE_HOME environment variable specifies the directory in which the Oracle software is installed. The
PATH environment variable specifies a list of directories that contain the command line utilities. The
CLASSPATH environment variable specifies a list of Java class libraries and directories that are used by the various Java utilities.
The ORACLE_HOME Environment Variable
You should add a system environment variable named
ORACLE_HOME using the System Properties dialog. The
ORACLE_HOME environment variable should be set to the directory where the Oracle software is installed. Many Oracle applications and utilities depend on the
ORACLE_HOME environment variable to point the way to the Oracle software directory.
To set your
ORACLE_HOME environment variable using Windows NT 4.0, you should use the System Properties dialog in the Control Panel. Figure 1 shows an example of the System Properties dialog, along with an
ORACLE_HOME environment variable (Windows 2000 has a similar dialog).
To set your
ORACLE_HOME environment variable using the Bash shell with Linux, you should add lines to your
.bash_profile file that are similar to the following:
ORACLE_HOME=installation_directory export ORACLE_HOME
installation_directory is the directory where the Oracle software is installed.
Pages: 1, 2