SQL/MX Programming Manual for Java

SQL/MX Programming Considerations
HP NonStop SQL/MX Programming Manual for Java523726-003
4-9
Dynamic CONTROL Statements
during customization because it occurs immediately before the statically compiled
statements in line order:
try {
if (deptnum == 3100)
{
#sql [ctx] {CONTROL QUERY DEFAULT CATALOG 'CAT1'};
}
else
{
#sql [ctx] {CONTROL QUERY DEFAULT CATALOG 'CAT2'};
}
#sql [ctx] { /* Static SELECT statement */ };
#sql [ctx] { /* Dynamic UPDATE statement */ };
#sql [ctx] { /* Static UPDATE statement */ };
#sql [ctx] { /* Dynamic SELECT statement */ };
}
Connection Context of Dynamic CONTROL Statements
Dynamic CONTROL statements affect only those dynamic SQL statements that share
the same JDBC connection. The JDBC/MX driver creates a different SQL context for
each JDBC connection.
Example
In this example, the dynamic CONTROL QUERY DEFAULT statement affects only the
dynamic UPDATE and SELECT statements because they share the same JDBC
connection, even though they have different connection contexts:
ctx1 = SQLMXCtx.getDefaultContext();
#sql [ctx1] {CONTROL QUERY DEFAULT SIMILARITY_CHECK 'off'};
#sql [ctx1] { /* Dynamic UPDATE statement */ };
#sql { /* Dynamic INSERT statement */ };
ctx2 = new SQLMXCtx(ctx1);
#sql [ctx2] { /* Dynamic SELECT statement */ };
ctx2.close();
#sql { /* Dynamic DELETE statement */ };