Oracle8i SQLJ Developer's Guide and Reference
Release 3 (8.1.7)

Part Number A83723-01


Solution Area



Go to previous page Go to beginning of chapter Go to next page

Testing the Setup

You can test your database, JDBC, and SQLJ setup using demo applications defined in the following source files:

There is also a Java properties file,, that helps you set up your database connection. You must edit this file to set appropriate user, password, and URL values.

These demo applications are provided with your SQLJ installation in the demo directory:

[Oracle Home]/sqlj/demo

You must edit some of the source files as necessary and translate and/or compile them as appropriate (as explained in the following subsections).

The demo applications provided with the Oracle SQLJ installation refer to tables on a database account with user name scott and password tiger. Most Oracle installations have this account. You can substitute other values for scott and tiger if desired.


Running the demo applications requires that the demo directory be the current directory and that the current directory (".") be in your CLASSPATH, as described earlier.  

Set Up the Runtime Connection

This section describes how to update the file to configure your database connection for runtime. The file is in the demo directory and looks something like the following:

# Users should uncomment one of the following URLs or add their own.
# (If using Thin, edit as appropriate.)
# User name and password here

(User scott and password tiger are used for the demo applications.)

There is also a listing of in "Runtime Connection Properties File".

Connecting with an Oracle JDBC Driver

If you are using a JDBC OCI driver (OCI8 or OCI7), then uncomment the oci8 URL line or the oci7 URL line, as appropriate, in the file.

If you are using the JDBC Thin driver, then uncomment the thin URL line in and edit it as appropriate for your database connection. Use the same URL that was specified when your JDBC driver was set up.

Connecting with a non-Oracle JDBC Driver

If you are using a non-Oracle JDBC driver, then add a line to to set the appropriate URL, as follows:


Use the same URL that was specified when your JDBC driver was set up.

You must also register the driver explicitly in your code (this is performed automatically in the demo and test programs if you use an Oracle JDBC driver). See "Driver Selection and Registration for Runtime".

Create a Table to Verify the Database

The following tests assume a table called SALES. If you compile and run TestInstallCreateTable as follows, it will create the table for you if the database and your JDBC driver are working and your connection is set up properly in the file:

java TestInstallCreateTable


If you already have a table called SALES in your schema and do not want it altered, edit to change the table name. Otherwise, your original table will be dropped and replaced.  

If you do not want to use TestInstallCreateTable, you can instead create the SALES table using the following command in a database command-line processor (such as SQL*Plus):

      ITEM_NAME CHAR(30),

Verify the JDBC Driver

If you want to further test the Oracle JDBC driver, use the TestInstallJDBC demo.

Verify that your connection is set up properly in as described above, then compile and run TestInstallJDBC:

java  TestInstallJDBC 

The program should print:

Hello, JDBC! 

Verify the SQLJ Translator and Runtime

Now translate and run the TestInstallSQLJ demo, a SQLJ application that has similar functionality to TestInstallJDBC. Use the following command to translate the source:

sqlj  TestInstallSQLJ.sqlj

After a brief wait you should get your system prompt back with no error output. Note that this command also compiles the application and customizes it to use an Oracle database.

On Solaris, the sqlj script is in [Oracle Home]/bin, which should already be in your PATH as described above. (On Windows, use the sqlj.exe executable in the bin directory.) The SQLJ file has the class files for the SQLJ translator and runtime, is located in [Oracle Home]/sqlj/lib, and should already be in your CLASSPATH as described above.

Now run the application:

java  TestInstallSQLJ

The program should print:

Hello, SQLJ!

Verify the SQLJ Translator Connection to the Database

If the SQLJ translator is able to connect to a database, then it can provide online semantics-checking of your SQL operations during translation. The SQLJ translator is written in Java and uses JDBC to get information it needs from a database connection that you specify. You provide the connection parameters for online semantics-checking using the sqlj script command line or using a SQLJ properties file (called by default).

While still in the demo directory, edit the file and update, comment, or uncomment the sqlj.password, sqlj.url, and sqlj.driver lines, as appropriate, to reflect your database connection information, as you did in For some assistance, see the comments in the file.

Following is an example of what the appropriate driver, URL, and password settings might be if you are using the Oracle JDBC OCI8 driver (the user name will be discussed next):


Online semantics-checking is enabled as soon as you specify a user name for the translation-time database connection. You can specify the user name either by uncommenting the sqlj.user line in the file or by using the -user command-line option. (The user, password, URL, and driver options all can be set either on the command line or in the properties file. This is explained in "Connection Options".)

You can test online semantics-checking by translating the file TestInstallSQLJChecker.sqlj (located in the demo directory) as follows (or using another user name if appropriate):

sqlj -user=scott TestInstallSQLJChecker.sqlj

This should produce the following error message if you are using one of the Oracle JDBC drivers:

TestInstallSQLJChecker.sqlj:41: Warning: Unable to check SQL query. Error 
returned by database is: ORA-00904: invalid column name

Edit TestInstallSQLJChecker.sqlj to fix the error on line 41. The column name should be ITEM_NAME instead of ITEM_NAMAE. Once you make this change, you can translate and run the application without error using the following commands:

sqlj -user=scott TestInstallSQLJChecker.sqlj
java  TestInstallSQLJChecker

If everything works, this prints:

Hello, SQLJ Checker!

Go to previous page
Go to beginning of chapter
Go to next page
Copyright © 1996-2000, Oracle Corporation.

All Rights Reserved.


Solution Area