Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id EE9F86336A0 for ; Mon, 2 Mar 2009 19:53:47 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 11539-10 for ; Mon, 2 Mar 2009 19:53:44 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mx02.burntmail.com (7a.3f.5746.static.theplanet.com [70.87.63.122]) by mail.postgresql.org (Postfix) with ESMTP id 1DB45633559 for ; Mon, 2 Mar 2009 19:53:44 -0400 (AST) Received: from pool-173-79-61-125.washdc.fios.verizon.net ([173.79.61.125] helo=[127.0.0.1]) by mx02.burntmail.com with esmtpa (Exim 4.63) (envelope-from ) id 1LeHwt-00040F-Fu for pgsql-jdbc@postgresql.org; Mon, 02 Mar 2009 17:53:27 -0600 Message-ID: <49AC7173.606@burntmail.com> Date: Mon, 02 Mar 2009 18:53:23 -0500 From: Guy Rouillier User-Agent: Thunderbird 2.0.0.19 (Windows/20081209) MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: Re: Cannot create JDBC driver of class '' for connect URL 'null' References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 090302-0, 03/02/2009), Outbound message X-Antivirus-Status: Clean X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200903/5 X-Sequence-Number: 19335 Stanley Wong wrote: > Hi, > > I encounter a problem regarding setting up a JNDI Datasource at Tomcat > with PostgreSQL under Linux Suse 10.3 environment. This is the > exception. > > org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC > driver of class '' for connect URL 'null' Using your sample works for me with the changes indicated below. > > I wonder if there are some additional settings that I may have > forgotten. > > Would you give me a hand here? > > Stanley > > > > Here is what I do: > > 0) Ensure the postgreSQL.jar is stored inside the tomcat/lib > > 1) Create a context.xml in the META-INF. The context.xml defines the > context below: > > > crossContext="true" reloadable="true" debug="1"> Take out path and docBase. Since you are defining a context, Tomcat knows those. > 3) Use the following code to get the connection: > > public Connection getConnection() { > Connection conn = null; > Context initCtx; > try { > initCtx = new InitialContext(); > DataSource ds = (DataSource) initCtx > > lookup("java:comp/env/jdbc/postgres"); You are missing a decimal point between initCtx and lookup. Where are you running this code? I created a sample JSP page dbtest.jsp and placed it in the root directory of the context. I called my context text, so under that I had dbtest.jsp, META-INF and WEB-INF. Since you are creating the datasource within the context, only Java code running within the context has access to it. -- Guy Rouillier