디비연동하는 파일인데요
백문이불여일타 456p
Context initContext= new initialContext();
Context envContext =(context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/myoracle");
Connection conn=ds.getConnection();
out.prinln("DBCP 연동 성공");
이부분을 좀 자세히 설명해주시면 감사요
( 0-0)/ 겟콘넥션 메서드로 연결한다는건 알겠는데
그전에 콘텍스트 객체가 만들어지는 과정을 모르겠어요
자바 프로그래밍에서 분산된 여러 자원에 접근하기 위해 별도로 확장패키지를 제공하는데요.
javx.naming 패키지가 그것입니다.
DB 연결도 외부 자원에 접근해야 하기 때문에 이 패키지에 있는 클래스나 인터페이스를 쓰는 것이구요.
DBCP 연결할 때, 아래와 같은 순서로 연결을 얻어오는 것은 어찌보면 외워야 될 것 같기도 합니다.
약속처럼 생각하면 될 것 같은데요.
// 다음 두 코드는 현재 환경의 설정정보를 얻어오는 역할을 합니다.
Context initContext= new initialContext();
Context envContext =(context)initContext.lookup("java:/comp/env");
// 그 다음에 Data Source를 찾고
DataSource ds = (DataSource)envContext.lookup("jdbc/myoracle");
// 풀로부터 커넥션을 할당하는 것이죠.
Connection conn=ds.getConnection();
좀더 들어가서, intial Context는 문서를 찾아보니,
In JNDI, every name is relative to a context. There is no notion of "absolute names." An application can bootstrap by obtaining its first context of class InitialContext :
public class InitialContext implements Context {
public InitialContext()...;
...
}
The initial context contains a variety of bindings that hook up the client to useful and shared contexts from one or more naming systems, such as the namespace of URLs or the root of DNS.
위와 같이 정의되어 있더라구요.
모든 이름은 상대경로라고 하네요. 절대경로란 개념은 없다고 하고. 암튼 애플리케이션이 로드가 되려면 처음에 intialContext 클래스의 첫번째 컨텍스트를 얻어와야 한다고 되어 있으니, 커넥션 풀이라는 자원에 접근하기 위해
맨 먼저 initialContext 생성자를 이용해서 Context 객체를 생성하는 작업을 처음으로 하는 것 같습니다.
저도 연구해본 게 여기까지인데요. 우선은 저자분께 자세한 내용에 대해 설명을 해주실 수 있냐고 요청을 드렸습니다.
빠른 조언을 드릴 수 있도록 해보겠습니다.
감사합니다.