Do you have already connected to a postgresql db using a java app? Are you sure the parameters are correct? What is "public"? Where did you put the postgresql.jar? Do you have a file named hsql.jar? Can you remove it?
-----Original Message----- From: Przemyslaw Kowalczyk [mailto:[EMAIL PROTECTED]] Sent: 02 July 2002 12:09 To: 'Tomcat Users List' Subject: Tomcat 4.0.4, jndi, jdbc and postgresql [long] Hi I've just started to write servlets. Servlets that only do processing, without connecting to database work fine, but I have some problems to get the connection with postgresql via jdbc work. Tomcat: 4.0.4 (on linux) Postgresql: 7.2.1 (on linux) Jdbc: pgjdbc2.jar (from jdbc.postgresql.org) The servlet is quite simple: import java.io.*; import java.util.*; import java.sql.*; import javax.sql.*; import javax.naming.*; import javax.servlet.*; import javax.servlet.http.*; public class InfoServlet extends HttpServlet { Connection con; private boolean conFree = true; public void init() throws ServletException { try { Context initCtx = new InitialContext(); Context envCtx = (Context)initCtx.lookup("java:comp/env"); DataSource ds = (DataSource) envCtx.lookup("jdbc/BookDB"); Connection con = ds.getConnection(); } catch (Exception ex) { throw new ServletException("Couldn't open connection to database: " + ex.getMessage()); } } public void destroy() { try { con.close(); } catch (SQLException ex) { System.out.println(ex.getMessage()); } } public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); // set content-type header before accessing the Writer response.setContentType("text/html"); response.setBufferSize(8192); PrintWriter out = response.getWriter(); // then write the data of the response out.println("<html>" + "<head><title>Duke's Bookstore</title></head>"); } } in web/WEB-INF/web.xml I defined: <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <display-name>Currency Converter Application</display-name> <description> Test servlet </description> <servlet> <servlet-name>info</servlet-name> <display-name>info</display-name> <description>no description</description> <servlet-class>InfoServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>info</servlet-name> <url-pattern>/info</url-pattern> </servlet-mapping> <session-config> <session-timeout>30</session-timeout> </session-config> <resource-ref> <res-ref-name>jdbc/BookDB</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Containter</res-auth> </resource-ref> </web-app> And in server.xml in the contex of the application: <Context path="/bookstore" docBase="bookstore" debug="0" reloadable="true" crossContext="true"> <Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_bookstore_log." suffix=".txt" timestamp="true"/> <Resource name="jdbc/BookDB" auth="Container" type="javax.sql.DataSource"/> <ResourceParams name="jdbc/BookDB"> <parameter> <name>user</name> <value>java</value> </parameter> <parameter> <name>password</name> <value>java</value> </parameter> <parameter> <name>driverClassName</name> <value>org.postgresql.Driver</value> </parameter> <parameter> <name>driverName</name> <value>jdbc:postgresql:public</value> </parameter> </ResourceParams> </Context> I've tried a few different driverName parameters: (restarting Tomcat after each change) jdbc:postgresql://localhost/public jdbc:postgresql://full.server.name/public jdbc:postgresql:public jdbc:postgresql://localhost/ But, despite the parameters, I always get the following error: exception javax.servlet.ServletException: Couldn't open connection to database: Exception creating DataSource: org.hsql.jdbcDriver at InfoServlet.init(Unknown Source) at javax.servlet.GenericServlet.init(GenericServlet.java:258) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:918) .... {cut} I have no idea why Tomcat wants to connect using hsql driver. I grepped through tomcat directory and found only one reference to this driver (in examples section). I removed event the sample section, restarted Tomcat but it didn't help. Does anyone know what is wrong? regards Przem -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> **** DISCLAIMER **** "This e-mail and any attachments thereto may contain information which is confidential and/or protected by intellectual property rights and are intended for the sole use of the recipient(s) named above. Any use of the information contained herein (including, but not limited to, total or partial reproduction, communication or distribution in any form) by persons other than the designated recipient(s) is prohibited. If you have received this e-mail in error, please notify the sender either by telephone or by e-mail and delete the material from any computer. Thank you for your cooperation." -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>