【发布时间】:2011-03-16 12:06:24
【问题描述】:
我正在尝试使用 Jndi 从 tomcat 服务器获取数据库连接。在那种情况下,如果是 tomcat,我的 java.naming.provider.url 会是什么??
【问题讨论】:
标签: tomcat
我正在尝试使用 Jndi 从 tomcat 服务器获取数据库连接。在那种情况下,如果是 tomcat,我的 java.naming.provider.url 会是什么??
【问题讨论】:
标签: tomcat
这个问题不是很清楚。根据 JNDI documentation,url 属性以 rmi://server:port 格式指定注册表的位置。因此,至少当您最初为在注册表中注册的对象的绑定创建命名上下文时,您需要传入注册表的位置。您可以找到示例代码here:
// select the registry service provider as the initial context
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory");
// specify where the registry is running
env.put(Context.PROVIDER_URL, "rmi://server:1099");
// create an initial context that accesses the registry
Context ctx = new InitialContext(env);
// now, the names stored in registry can be listed
NamingEnumeration enum = ctx.list("");
【讨论】: