Return-Path: Delivered-To: apmail-jakarta-tomcat-user-archive@www.apache.org Received: (qmail 64168 invoked from network); 3 Dec 2003 07:56:49 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 3 Dec 2003 07:56:49 -0000 Received: (qmail 47558 invoked by uid 500); 3 Dec 2003 07:56:08 -0000 Delivered-To: apmail-jakarta-tomcat-user-archive@jakarta.apache.org Received: (qmail 47539 invoked by uid 500); 3 Dec 2003 07:56:07 -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 47518 invoked from network); 3 Dec 2003 07:56:05 -0000 Received: from unknown (HELO Firewall.ev.co.yu) (194.247.214.130) by daedalus.apache.org with SMTP; 3 Dec 2003 07:56:05 -0000 Received: by Firewall.ev.co.yu; (5.65v4.0/1.3/10May95) id AA00853; Thu, 3 Dec 1998 08:58:03 +0100 Received: from ev.co.yu (Brigitte.ev.co.yu [192.168.61.110]) by Uprava.ev.co.yu (8.12.10/8.12.10) with ESMTP id hB37sSAC018724 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 3 Dec 2003 08:54:31 +0100 (MET) Message-Id: <3FCD97D6.40204@ev.co.yu> Date: Wed, 03 Dec 2003 08:59:18 +0100 From: Nikola Milutinovic Organization: EPS Elektrovojvodina User-Agent: Mozilla/5.0 (Windows; U; WinNT4.0; en-US; rv:1.5) Gecko/20031007 X-Accept-Language: en, sr Mime-Version: 1.0 To: Tomcat Users List Subject: Re: Servlets with JDBC connectivity References: <67A8A2CC-253F-11D8-BEC7-0030656EC0E4@mac.com> <200312032022.56558.peter.harrison@nothingbutnet.co.nz> In-Reply-To: <200312032022.56558.peter.harrison@nothingbutnet.co.nz> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-milter (http://www.amavis.org/) X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Peter Harrison wrote: > On Wed, 03 Dec 2003 16:18, Todd O'Bryan wrote: > > >>How do people handle this elegantly? The requirements are: a single, >>globally visible (within a webapp) database interface and the ability >>to access multiple databases easily. > > > The first point is to use a singleton to set up the database connection - or > more correctly the connection pool. This way you can request a connection and > return it to the pool easily. Of course every time you use one you will have > to use try-catch blocks. Sorry no way around that. Both Tomcat and J2EE specification support javax.sql.DataSource objects over JNDI. That is how we handle it elegantly. A DataSource object is specified by the administrator and created by the container. Container then deploys it under specified JNDI name. A servlet (or EJB) can then lookup this object and use it, something like this: import java.sql.*; import javax.sql.*; import javax.naming.*; InitialContext ic = new InitialContext(); DataSource ds = (DataSource)ic.lookup( "java:comp/env/jdbc/MyDataSource" ); Connection conn = ds.getConnection(); Nix. --------------------------------------------------------------------- To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: tomcat-user-help@jakarta.apache.org