SQLJ 연결 기술 2: JDBC DriverManager 인터페이스
SQLJ 연결 기술 2는 연결 작성을 위한 기본 도구로 DriverManager 인터페이스를 사용합니다.
프로시저
SQLJ 연결 기술 2를 사용하려면 다음 단계를 수행하십시오.
예
#sql context Ctx; // Create connection context class Ctx 1
String userid="dbadm"; // Declare variables for user ID and password
String password="dbadm";
String empname; // Declare a host variable
…
try { // Load the JDBC driver
Class.forName("com.ibm.db2.jcc.DB2Driver"); 2
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
Connection jdbccon= 3
DriverManager.getConnection("jdbc:db2://sysmvs1.stl.ibm.com:5021/NEWYORK",
userid,password);
// Create JDBC connection object jdbccon
jdbccon.setAutoCommit(false); // Do not autocommit
Ctx myConnCtx=new Ctx(jdbccon); 4
// Create connection context object myConnCtx
// for the connection to NEWYORK
#sql [myConnCtx] {SELECT LASTNAME INTO :empname FROM EMPLOYEE
WHERE EMPNO='000010'};
// Use myConnCtx for executing an SQL statement