X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 49C0C5E46FD for ; Fri, 27 Aug 2004 20:30:52 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 99677-09 for ; Fri, 27 Aug 2004 23:30:46 +0000 (GMT) Received: from mail.multimedia-werkstatt.com (unknown [195.243.149.235]) by svr1.postgresql.org (Postfix) with ESMTP id 947D95E46F5 for ; Fri, 27 Aug 2004 20:30:44 -0300 (ADT) Received: from [192.168.2.40] (helo=multimedia-werkstatt.com) by mail.multimedia-werkstatt.com with esmtp (Exim 4.12) id 1C0qAq-0001zV-00; Sat, 28 Aug 2004 01:30:24 +0200 Message-ID: <412FC4DF.5020007@multimedia-werkstatt.com> Date: Sat, 28 Aug 2004 01:33:51 +0200 From: Harry Schittler User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.6b) Gecko/20031205 Thunderbird/0.4 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Mag Gam Cc: pgsql-jdbc@postgresql.org Subject: Re: JNDI Datasource example References: <1093636380.30796.203209982@webmail.messagingengine.com> In-Reply-To: <1093636380.30796.203209982@webmail.messagingengine.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200408/151 X-Sequence-Number: 10873 Mag Gam wrote: >Does anyone have a GOOD example of PostgreSQL with Tomcat using JNDI? I >was looking at >http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html >but the code they provided really did not help. If someone has some code >please post it. Thanks in advance! > > Just case you were using the same approach as I did and used the tomcat admin application to create the JNDI resource Lets assume a datasource named "jdbc/testds" and a context named "testctx" put your postgres jdbc driver into $TOMCAT/common/lib, restart Tomcat Create the datasource using the tomcat admin application, use org.postgresql.Driver as driverClass and jdbc:postgresql://localhost/ as URL insert the following in your applications WEB-INF/web.xml: DB Connection jdbc/testds javax.sql.DataSource Container Create a META-INF/context.xml and insert: Use the following code to lookup the datasource: try{ Context ctx = new InitialContext(); if(ctx == null ) throw new Exception("JNDI could not create InitalContext "); Context envContext = (Context)ctx.lookup("java:/comp/env"); datasource = (DataSource)envContext.lookup(jndiName); } catch(Exception e) { e.printStackTrace(); } this works for me... cu Harry