0
IAM이 JNDI를 사용하여 mysql에 연결하려고합니다. 그러나 예외를 보여JNDI를 사용하는 javax.naming.NoInitialContextException
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:
참조 내 코드 :
VendorDataSource vds = new VendorDataSource();
vds.setServerName("localhost");
vds.setDatabaseName("jnditest");
vds.setDescription("The data source for inventory and personnel");
try {
ctx = new InitialContext();
ctx.bind("jdbc/myds", vds);
} catch (NamingException e1) {
e1.printStackTrace();
}
try {
ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("jdbc/myds");
Connection conn = ds.getConnection("root", "password");
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
그리고 오류 메시지 :
javax.naming.NoInitialContextException: 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
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.bind(Unknown Source)
at samplemariadb.DataSourceConnectivity.main(DataSourceConnectivity.java:33)
이 방법도 시도해보십시오. 그러나 사이트에서 fscontext.jar 파일을 다운로드 할 수 없습니다. fscontext.jar 파일을 다운로드 할 수있는 적절한 경로를 제공 할 수 있습니까? – Haseena
필자가 알고있는 한, Java Web Services Developer Pack (http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-jwsdp-419428.html)에 포함되어 있지만 그게 당신이 필요한지 확실하지 않습니다. – richardtz