SQLJ connection technique 5: Use a previously created connection context
SQLJ connection technique 5 uses a previously created connection context to connect to the data source.
About this task
Example
#sql context Ctx;
…
// Create connection context object oldCtx
Program test.sqlj receives
oldCtx as a parameter and uses oldCtx as the argument of its connection context
constructor: void useContext(sqlj.runtime.ConnectionContext oldCtx)
// oldCtx was created in CtxGen.sqlj
{
Ctx myConnCtx=
new Ctx(oldCtx); // Create connection context object myConnCtx
// from oldCtx
#sql [myConnCtx] {SELECT LASTNAME INTO :empname FROM EMPLOYEE
WHERE EMPNO='000010'};
// Use myConnCtx for executing an SQL statement
…
}