[OT] : How to get a connection from Tomcat DBCP from a remote application?
Hi, I am using Tomcat 5.5.7 and configured DBCP properly to work with Oracle 9i. Everything is working fine if I try to get the connection from the Pool from an application deployed in Tomcat. However if I try to get the connection from the Pool from an application which is not deployed in Tomcat (remote client), I am getting not bound exceptions. Here is the code: import java.util.*; import javax.naming.*; import javax.sql.DataSource; public class ClientTest { public static void main(String[] args) { Context ctx = null; try { Hashtable props = new Hashtable(); props.put(Context.INITIAL_CONTEXT_FACTORY, org.apache.naming.java.javaURLContextFactory); props.put(Context.URL_PKG_PREFIXES, org.apache.catalina.util.naming); ctx = new InitialContext(props); DataSource dataSource = (DataSource)ctx.lookup(java:/comp/env/jdbc/test); } catch(Exception e) { e.printStackTrace(); } } } Stacktrace shows: javax.naming.NameNotFoundException: Name java: is not bound in this Context at org.apache.naming.NamingContext.list(NamingContext.java:344) at org.apache.naming.NamingContext.list(NamingContext.java:367) at javax.naming.InitialContext.list(InitialContext.java:387) What am I doing wrong? Is it allowed to access the Pool from remote client in first place? Thanks in advance, Appa __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
Re: [OT] : How to get a connection from Tomcat DBCP from a remote application?
On Sun, May 01, 2005 at 05:46:22PM -0700, appa rao wrote: : However if I try to get the connection from the Pool from an application which is not deployed in Tomcat (remote client), I am getting not bound exceptions. This makes sense. Keep in mind, JNDI is just a lookup/storage service for objects. The container maintains its own (internal) JNDI service, and one object it stores there is the DataSource that represents your connection pool. When last I checked (admittedly, it's been a while), Tomcat's JNDI service is not available outside of the container. So ask yourself this: does your non-webapp code really need a DataSource pulled from JNDI? (find a JNDI service, create a DataSource, store it) or does it just need access to a DataSource, period? (abstract your data access into a separate layer, such that your code doesn't know from where its gets Connection objects) Either way, someone will have to configure the connections for the non-webapp code; one convenience provided by containers is that they take care of instantiating/configuring the DataSource for you (based on your entries in server.xml/context.xml). -QM -- software -- http://www.brandxdev.net/ tech news -- http://www.RoarNetworX.com/ code scan -- http://www.JxRef.org/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]