SQLJ connection technique 4: JDBC DataSource interface
SQLJ connection technique 4 uses the JDBC DataSource as the underlying means for creating the connection. This technique requires that the DataSource is registered with JNDI.
Procedure
To use SQLJ connection technique 4, follow these steps:
Example
jdbc/sampledb.
The connection requires a user ID and password.#sql public static context Ctx
with (dataSource="jdbc/sampledb"); 2
// Create connection context class Ctx
String userid="dbadm"; // Declare variables for user ID and password
String password="dbadm";
String empname; // Declare a host variable
…
Ctx myConnCtx=new Ctx(userid, password); 3
// Create connection context object myConnCtx
// for the connection to jdbc/sampledb
#sql [myConnCtx] {SELECT LASTNAME INTO :empname FROM EMPLOYEE
WHERE EMPNO='000010'};
// Use myConnCtx for executing an SQL statement