From tomcat-user-return-119480-apmail-jakarta-tomcat-user-archive=jakarta.apache.org@jakarta.apache.org Fri Jan 14 21:54:41 2005 Return-Path: Delivered-To: apmail-jakarta-tomcat-user-archive@www.apache.org Received: (qmail 64364 invoked from network); 14 Jan 2005 21:54:40 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 14 Jan 2005 21:54:40 -0000 Received: (qmail 66603 invoked by uid 500); 14 Jan 2005 21:54:21 -0000 Delivered-To: apmail-jakarta-tomcat-user-archive@jakarta.apache.org Received: (qmail 66581 invoked by uid 500); 14 Jan 2005 21:54:20 -0000 Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: 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 66567 invoked by uid 99); 14 Jan 2005 21:54:20 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: local policy) Received: from znx208-2-156-007.znyx.com (HELO lotus.znyx.com) (208.2.156.7) by apache.org (qpsmtpd/0.28) with ESMTP; Fri, 14 Jan 2005 13:54:19 -0800 Received: from znyx.com ([208.2.156.111]) by lotus.znyx.com (Lotus Domino Release 5.0.11) with ESMTP id 2005011413534148:31995 ; Fri, 14 Jan 2005 13:53:41 -0800 Message-ID: <41E84029.5040308@znyx.com> Date: Fri, 14 Jan 2005 13:56:57 -0800 From: Alan Deikman User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.6) Gecko/20040113 X-Accept-Language: en-us, en MIME-Version: 1.0 To: tomcat-user@jakarta.apache.org Subject: Question about JNDI resources X-MIMETrack: Itemize by SMTP Server on Lotus/Znyx(Release 5.0.11 |July 24, 2002) at 01/14/2005 01:53:41 PM, Serialize by Router on Lotus/Znyx(Release 5.0.11 |July 24, 2002) at 01/14/2005 01:53:44 PM, Serialize complete at 01/14/2005 01:53:44 PM Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=ISO-8859-1; format=flowed X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N I'm just learning this stuff, but having good success so far. In my SQL-backed bean I use a JDBCResource as per the documentation: protected static Connection getConnection() { //System.out.println("User.getConnection Attempting to get connection"); try { Context initContext = new InitialContext(); Context envContext = (Context)initContext.lookup("java:/comp/env"); DataSource ds = (DataSource) envContext.lookup("jdbc/zzzz"); Connection conn = ds.getConnection(); return conn; } catch (NamingException ne) { System.out.println("User.getConnection caught Naming exception"); System.out.println(ne.toString()); } catch (SQLException sqle) { System.out.println("User.getConnection caught SQL exception"); System.out.println(sqle.toString()); } This works, way cool. My question is do I need to look up two new Context objects and a new DataSource each time I get a connection? Or can I just store initContext, envContext, and ds in static variables and load them just once for all instances of the class? If that works, why don't the examples do it that way? Alan Deikman ZNYX Networks --------------------------------------------------------------------- To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: tomcat-user-help@jakarta.apache.org