Fundamentals of embedded SQLJ programs

Each SQLJ statement in an Embedded SQLJ program is identified by #sql at the beginning of the statement. The SQLJ translator recognizes #sql and translates the rest of the statement into Java™ code using JDBC calls.

You can use a class called ConnectionManager (located in a file in the /demo/sqlj directory) to initiate a JDBC connection. The ConnectionManager class uses a JDBC driver and a database URL to connect to a database. Database URLs are described in Database URLs.

To enable your embedded SQLJ program to connect to a database, you assign values to the following data members of the ConnectionManager class in the file /demo/sqlj/ConnectionManager.java:
Member Description

UID

The user name

PWD

The password for the user name

DRIVER

The JDBC driver

DBURL

The URL for the database

You must include the directory that contains your ConnectionManager.class file (produced when you compile ConnectionManager.java) in your CLASSPATH environment variable definition.

Your Embedded SQLJ program connects to the database by calling the initContext() method of the ConnectionManager class, as follows:
ConnectionManager.initContext();

The ConnectionManager class provides details about the functionality of the initContext() method.

As an alternative to using the ConnectionManager class, you can write your own input methods to read the values of user name, password, driver, and database URL from a file or from the command line.

The connection context that you set up is the default connection context; all #sql statements execute within this context, unless you specify a different context. For information about using nondefault connection contexts, see Nondefault connection contexts.