IBM에서 출판 한 Managing database connections with JDBC을 공부 중입니다. 그것은 오래된 것들입니다 (2001). 그들은 JNDI를 사용하고 있습니다. 내가 그들의 코드를 구현하려고 할 때 :InitialContext 공장 오류
try {
Hashtable env = new Hashtable();
env.put(
Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory");
// Create the initial context
Context ctx = new InitialContext(env);
// Here we create the actual DataSource and then set the relevant
// parameters.
TdsDataSource ds = new TdsDataSource();
ds.setServerName(serverName);
ds.setPortNumber(portNumber);
ds.setDatabaseName(databaseName);
ds.setUser(login);
ds.setPassword(password);
ds.setDescription("JDBC DataSource Connection");
// Now we bind the DataSource object to the name we selected earlier.
ctx.bind(filePath, ds);
ctx.close();
// Generic Exception handler, in practice, this would be replaced by an
// appropriate Exception handling hierarchy.
} catch (Exception ex) {
System.err.println("ERROR: " + ex.getMessage());
}
을하지만 더 "com.sun.jndi.fscontext.RefFSContextFactory"파일 시스템 서비스 제공 업체가 없다는 것을 알게되었습니다. 그런 다음 코드를 다음과 같이 변경했습니다 (Initialize Data Source Properties에서). 내가 아직도는 Context.INITIAL_CONTEXT_FACTORY 요구 생각
ERROR: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
:
OracleDataSource ods = new OracleDataSource();
ods.setDriverType("oci");
ods.setServerName("dlsun999");
ods.setNetworkProtocol("tcp");
ods.setDatabaseName("816");
ods.setPortNumber(1521);
ods.setUser("scott");
ods.setPassword("tiger");
Context ctx = new InitialContext();
ctx.bind("jdbc/sampledb", ods);
이 코드를 실행하려고
, 나는 다음과 같은 오류를 얻고있다. 어떤 해결책? 나는 아침부터 그것을 찾고있다.
그 중 하나가 작동하지 않습니다. 그것은 jdbc ("jdbc/sampledb"에서)가 문맥에 있지 않다는 것입니다. – kaushik