Return-Path: Delivered-To: apmail-jakarta-tomcat-user-archive@www.apache.org Received: (qmail 65333 invoked from network); 23 Aug 2005 15:25:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 23 Aug 2005 15:25:04 -0000 Received: (qmail 21656 invoked by uid 500); 23 Aug 2005 15:24:47 -0000 Delivered-To: apmail-jakarta-tomcat-user-archive@jakarta.apache.org Received: (qmail 21645 invoked by uid 500); 23 Aug 2005 15:24:47 -0000 Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Tomcat Users List" Reply-To: "Tomcat Users List" Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 21632 invoked by uid 99); 23 Aug 2005 15:24:47 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 23 Aug 2005 08:24:47 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [216.81.251.1] (HELO mail.printtime.com) (216.81.251.1) by apache.org (qpsmtpd/0.29) with SMTP; Tue, 23 Aug 2005 08:25:04 -0700 Received: from [216.243.225.47] (HELO [192.168.2.128]) by mail.printtime.com (Stalker SMTP Server 1.8b8) with ESMTP id S.0003480092 for ; Tue, 23 Aug 2005 10:28:24 -0500 Message-ID: <430B3F44.6070401@printtime.com> Date: Tue, 23 Aug 2005 10:22:44 -0500 From: Brian Cook Reply-To: bcook@printtime.com Organization: Print Time Inc. User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tomcat Users List Subject: Re: jndi question References: <4309E00A.4020809@gmail.com> <13224.1124725462@www37.gmx.net> <430A2AB9.9050804@gmail.com> In-Reply-To: <430A2AB9.9050804@gmail.com> Content-Type: multipart/mixed; boundary="------------020603080608010307020903" X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N --------------020603080608010307020903 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Yes you can use JNDI with out using JSTL. But the only way to configure it is to define the JNDI resources in the web.xml and context.xml files. Technically you should be able to use the globally defined JNDI resources in server.xml, and I have seen configuration set ups doing it when googling. But could never get them to work. This highlights another area of seemingly unneeded complication in Java/Unix development. Using JNDI for data sources which was supposed to help you save time requires that you redundantly define the JNDI resource in at lest 2 if not 3 places. The admin tool which was also supposed to help save time defines the JNDI resources in server.xml which does not really seem to be all that helpful. I am sure there is likely a reason for this but I am ignorant of it. The admin tool is also supposed to let you define JNDI resources per context but it errors out when ever I have tried it. My experience with the Tomcat Admin and Manager tools is that they are worthless. Of the few steps they try to help with more often that not they just return errors when you need to use it. I removed them both and have gone back to doing set ups manually and there has not been much of a time difference doing it this way. Any way for JNDI to work you will have to add the definition for it in both web.xml and context.xml in the <>/conf/Catalina/localhost/ folder. This seems counter productive since it makes your app less portable having the data base configuration details inside the context and by extent the WAR file but it is what you have to do to get it to work right now. I feel your pain I know it is frustrating spending hours debugging just the DB connection but todate that is the reality of Java web app development. It is why I fear we will all be .Net developers some day. Example : http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-resources-howto.html Context initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup("java:comp/env"); DataSource ds = (DataSource) envCtx.lookup("jdbc/EmployeeDB"); Connection conn = ds.getConnection(); ... use this connection to access the database ... conn.close(); Resource reference to a factory for java.sql.Connection instances that may be used for talking to a particular database that is configured in the server.xml file. jdbc/EmployeeDB javax.sql.DataSource Container Sean Rowe wrote: > Dirk, I'm sorry I didn't see the difference on the page you sent me to. > However, if there is a way I can do this without having to use jstl, I > would really like to know. I was hoping to put the code in a class > somewhere that my servlets could use. > > thanks, > sean > > Dirk Weigenand wrote: > >> Sean, >> >> >> >>> --- Urspr�ngliche Nachricht --- >>> Von: Sean Rowe >>> An: Tomcat Users List >>> Betreff: Re: jndi question >>> Datum: Mon, 22 Aug 2005 09:24:10 -0500 >>> >>> Thanks for responding Dirk. I've practically memorized the >>> documentation on the link you sent: >>> >>> // Obtain our environment naming context >>> Context initCtx = new InitialContext(); >>> Context envCtx = (Context) initCtx.lookup("java:comp/env"); >>> >>> // Look up our data source >>> DataSource ds = (DataSource) >>> envCtx.lookup("jdbc/EmployeeDB"); >>> >>> // Allocate and use a connection from the pool >>> Connection conn = ds.getConnection(); >>> ... use this connection to access the database ... >>> conn.close(); >>> >>> Whenever I try this, here's what I get (which led me to trying it the >>> way >>> I posted): >>> >>> javax.naming.NameNotFoundException: Name java:comp is not bound in this >>> Context >>> >>> >> >> >> No. Did you look at >> http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-datasource-examples-howto.html? >> >> >> I recommend putting the context definition in its own content.xml. On >> redeploying my application tomcat wouldn't find the driver class anymore. >> >> Mind you not the class itself but the definition of what class to load. >> >> This problem was solved by putting the context into context.xml. >> >> regards >> Dirk >> >> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org > > -- Brian Cook Digital Services Analyst Print Time Inc. bcook@printtime.com 913.345.8900 --------------020603080608010307020903 Content-Type: text/plain; charset=us-ascii --------------------------------------------------------------------- To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: tomcat-user-help@jakarta.apache.org --------------020603080608010307020903--