SQL/MX Programming Manual for Java
SQLJ Programming
HP NonStop SQL/MX Programming Manual for Java—523726-003
3-17
Explicit Connection Contexts
Generating a Profile for Each Connection Context Class
All SQL statements that are associated with the same connection context class are
included in the same profile. Because separate profiles exist for each connection
context class, you can use explicit connection contexts to store sets of database
objects in separate profiles. As a result, you can customize the database objects in one
profile differently from the database objects in another profile of the same SQLJ
program.
This subsection explains how to influence the creation of separate profiles for different
sets of database objects and why this technique is useful. For more information, see:
•
Coding an SQLJ Source File to Generate Separate Profiles on page 3-17
•
Customizing Each Profile With Different Options on page 3-19
Coding an SQLJ Source File to Generate Separate Profiles
To code the SQLJ source file:
1. Declare a connection context class for each connection context:
#sql context SQLMXCtx1;
#sql context SQLMXCtx2;
#sql context SQLMXCtx3;
2. Declare, initialize, and instantiate connection context objects for each connection
context class:
SQLMXCtx1 ctx1 = SQLMXCtx1.getDefaultContext();
SQLMXCtx2 ctx2 = SQLMXCtx2.getDefaultContext();
SQLMXCtx3 ctx3 = SQLMXCtx3.getDefaultContext();
Use a different connection context class for each instantiation. If you use the same
connection context class to instantiate different connection contexts, the SQL
statements associated with the different connection contexts are stored in the
same profile. In this example, the SQL statements associated with ctx1 and ctx2
are stored in the same profile:
ctx1 = SQLMXCtx.getDefaultContext();
#sql [ctx1] { /* SQL statement */ };
ctx2 = SQLMXCtx.getDefaultContext();
#sql [ctx2] { /* SQL statement */ };
#sql [ctx2] { /* SQL statement */ };