using Tomcat's database in external application

From: Larry S (dime0000_at_yahoo.com)
Date: 06/30/04


Date: 30 Jun 2004 08:01:52 -0700

hello - could someone point me to a doc that explains how to use the
database assigned to Tomcat in an external App? i've done some
reading, but can't find a concrete answer.. i have the following in
the external app, but keep getting a
"javax.naming.NameNotFoundException: Name java:comp is not bound in
thi
s Context" error:

public synchronized String getTest2() {
            Connection conn = null;
            
            try
            {
                Hashtable env = new Hashtable();
                env.put(Context.INITIAL_CONTEXT_FACTORY,
                  "org.apache.naming.java.javaURLContextFactory");
                env.put(Context.PROVIDER_URL,
                  "localhost:1099");

                Context ctx = new InitialContext(env);
                if (ctx == null)
                    return "No Context 1";

                Context envCtx = (Context)
ctx.lookup("java:comp/env");
                if (ctx == null)
                    return "No Context 2";
                
                DataSource ds =
(DataSource)envCtx.lookup("jdbc/MovieDB");

                if (ds != null)
                {
                    conn = ds.getConnection();
                }
            }
            catch(Exception e)
            {
                return "exception:" + e; // should log issue
            }
            
                return "got it";
        }