SQL/MX Programming Manual for Java
SQLJ Programming
HP NonStop SQL/MX Programming Manual for Java—523726-003
3-18
Explicit Connection Contexts
3. Associate each connection context with a particular set of SQL statements.
In this example, the ctx1 connection context is associated with database objects
in the SALES schema, ctx2 is associated with database objects in the PERSNL
schema, and ctx3 is associated with database objects in the INVENT schema.
Notice that the table names are unqualified:
#sql [ctx1] salesiter = {SELECT o.ordernum, o.salesrep,
d.partnum
FROM orders o, odetail d
WHERE o.ordernum = d.ordernum
AND qty_ordered > 30};
int order = 0;
int rep = 0;
while (true) {
#sql {FETCH :salesiter INTO :orderNum, :salesRep,
:partNum};
if (salesiter.endFetch())
break;
#sql [ctx1] {SELECT custname INTO :custName
FROM customer c, orders o
WHERE o.custnum = c.custnum
AND ordernum = :orderNum};
if (order != :orderNum) {
System.out.println();
System.out.println("Order: " + orderNum);
System.out.println("Customer: " + custName);
order = :orderNum;
}
#sql [ctx2] {SELECT first_name, last_name
INTO :firstName, :lastName
FROM employee
WHERE empnum = :salesRep};
if (rep != :salesRep) {
System.out.println("Sales rep: " + firstName + " "
+ lastName);
rep = :salesRep;
}
#sql [ctx3] {SELECT suppname INTO :suppName
FROM supplier s, partsupp p
WHERE p.suppnum = s.suppnum
AND partnum = :partNum};
System.out.println("Supplier: " + suppName);
}