当前位置: 动力学知识库 > 问答 > 编程问答 >

what would be java.naming.provider.url for tomcat

问题描述:

I m trying to fetch a database connection from a tomcat server using Jndi. In that case what would be my java.naming.provider.url in case of tomcat ??

网友答案:

The question isn't very clear. Per the JNDI documentation, the url property specifies the location of the registry in the format rmi://server:port. So at least when you're initially creating a naming context to bindings for the objects registered in the registry, you need to pass in the location of the registry. You can find sample code 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("");
分享给朋友:
您可能感兴趣的文章:
随机阅读: