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 90C7C5E46FB for ; Sat, 28 Aug 2004 10:09:25 -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 71457-10 for ; Sat, 28 Aug 2004 13:09:17 +0000 (GMT) Received: from frontend1.messagingengine.com (frontend1.messagingengine.com [66.111.4.30]) by svr1.postgresql.org (Postfix) with ESMTP id 5981E5E46E7 for ; Sat, 28 Aug 2004 10:09:15 -0300 (ADT) Received: from server3.messagingengine.com (server3.internal [10.202.2.134]) by frontend1.messagingengine.com (Postfix) with ESMTP id 73B33C143AD; Sat, 28 Aug 2004 09:09:19 -0400 (EDT) Received: by server3.messagingengine.com (Postfix, from userid 99) id 365B7191022; Sat, 28 Aug 2004 09:09:20 -0400 (EDT) Content-Disposition: inline Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="ISO-8859-1" MIME-Version: 1.0 X-Mailer: MIME::Lite 1.4 (F2.72; T1.001; A1.62; B3.01; Q3.01) Cc: pgsql-jdbc@postgresql.org References: <1093636380.30796.203209982@webmail.messagingengine.com> <412FC4DF.5020007@multimedia-werkstatt.com> Subject: Re: JNDI Datasource example In-Reply-To: <412FC4DF.5020007@multimedia-werkstatt.com> To: "Harry Schittler" Date: Sat, 28 Aug 2004 06:09:20 -0700 From: "Mag Gam" X-Sasl-Enc: eAgGFZ8KpqEMFUzAz5L5EA 1093698560 Message-Id: <1093698560.18627.203238436@webmail.messagingengine.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.9 tagged_above=0.0 required=5.0 tests=FROM_ENDS_IN_NUMS X-Spam-Level: X-Archive-Number: 200408/152 X-Sequence-Number: 10874 When I run this code snipnet, I get this problem. symbol : variable datasource location: class Test datasource = (DataSource)envContext.lookup(jndiName); ^ Test.java:22: cannot resolve symbol symbol : variable jndiName location: class Test datasource = (DataSource)envContext.lookup(jndiName); echo $CLASSPATH /usr/local/j2sdk1.4.2_05/lib/tools.jar:/usr/local/j2sdk1.4.2_05/jre/lib/rt.jar:/usr/local/jakarta-tomcat-4.1.30/common/lib/servlet.jar:/usr/local/jakarta-tomcat-4.1.30/common/lib/pg74.215.jdbc3.jar I looked everywhere, still problems with this datasource. Thanks! On Sat, 28 Aug 2004 01:33:51 +0200, "Harry Schittler" said: > 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: > > type="javax.sql.DataSource"/> > > > > 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