Nondefault connection contexts

This section explains how to use nondefault connection contexts. Embedded SQLJ uses a connection-context object to manage the connection to the database in which you want an SQL statement to execute. You can specify different connection-context objects for different SQL statements in the same Embedded SQLJ program, as shown in the sample program MultiConnect.sqlj included in this section.

To use a nondefault connection context

  1. Define the connection-context class by using an Embedded SQLJ connection statement. The syntax of the connection statement is as follows:
    #sql [modifiers] context java_class_name;
    modifiers
    A list of Java™ class modifiers: for example, public
    java_class_name
    The name of the Java class of the new connection context
  2. Create a connection-context object for connecting to the database.
  3. Specify the connection-context object in your Embedded SQLJ statement in parentheses following the #sql string.