Connection contexts in SQLJ routines
Each SQL statement in the SQLJ routines must explicitly indicate the ConnectionContext object, and that context must be explicitly instantiated in the Java™ method.
In the following SQLJ example, use of the default
context causes all threads to use the same connection context that
can result in unexpected failures.
class myClass
{
public static void myRoutine( short myInput )
{
DefaultContext ctx = DefaultContext.getDefaultContext();
#sql { some SQL statement };
}
}
In the following SQLJ example, each invocation
of the routine creates its own unique ConnectionContext object (and
underlying JDBC connection), which avoids unexpected interference
by concurrent threads.
#context MyContext;
class myClass
{
public static void myRoutine( short myInput )
{
MyContext ctx = new MyContext( "jdbc:default:connection", false );
#sql [ctx] { some SQL statement };
ctx.close();
}
}