How to use JNDI lookup from a JSP
843836Feb 12 2004 — edited Feb 12 2004Hello,
I know I should not be doing this (writing the lookup code in a JSP) but have to do it for some reasons.
I am using this code in my JSP:
try
{
Context ctx = new InitialContext();
dataSource = (DataSource)ctx.lookup("jdbc/mybillingora");
conn = dataSource.getConnection();
statement = conn.createStatement();
}
catch(Exception excep)
{
}
Is this code enough for a JNDI look up?? When I use this code, I get an exception:
"javax.naming.NameNotFound exception:jdbc/mybillingora"
Do I need to do something else??
Why do we use :
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"<some_context_factory>");
env.put(Context.PROVIDER_URL, PROVIDER_URL);
env.put(Context.SECURITY_PRINCIPAL, JNDI_USER);
env.put(Context.SECURITY_CREDENTIALS, JNDI_PWD);
InitialContext = new InitialDirContext(env);
**********************************
where JNDI_USER is the userid If ACL is configured at the JNDI server
where JNDI_PWD is the password If ACL is configured at the JNDI server
Context.INITIAL_CONTEXT_FACTORY is the initial Context factory and depends on ur JNDI service provider.
PROVIDER_URL is the url of the JNDI server containing protocol/ip/port
do i need to use this??
would appreciate your help on this....
Thanks