p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Apache Tomcat (http://p2p.wrox.com/forumdisplay.php?f=107)
-   -   trouble connecting to PostgreSQL with Tomcat /JSF (http://p2p.wrox.com/showthread.php?t=49674)

raindogs October 31st, 2006 01:31 PM

trouble connecting to PostgreSQL with Tomcat /JSF
 
Hello all,

I'm a bit new at JSF and Tomcat, and I'm having some trouble connecting to a Postgres DB. I'm using PostgreSQL 8.1 and Tomcat 5.0 and am trying to connect using the steps outlined in chapter 10 of the book "Core JavaServer Faces", but clearly I have something wrong. I've seen similar problems in various forums, but thus far none of the solutions have worked for me. My pages load fine, but any time I try to run the form that hits the DB, I get the following error:

SQL exception Cannot create JDBC driver of class '' for connect URL 'jdbc:postgresql://<host name>:5432/<database name>'

I'm fairly certain I have all the right Jar files and I know the DB connection parameters are right. I've pasted what I think are the relevant excerpts from "server.xml" and my application files below along with a list of all installed JAR files, any suggestions would be much appreciated.

*********
server.xml
*********

<DefaultContext>
<Resource name="jdbc/postgres" auth="Container" type="javax.sql.DataSource" />
<ResourceParams name="jdbc/postgres">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFact ory</value>
</parameter>
<parameter>
<name>DriveClassName</name>
<value>org.postgresql.Driver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:postgresql://<host name>:5432/<database name></value>
</parameter>
<parameter>
<name>username</name>
<value><username></value>
</parameter>
<parameter>
<name>password</name>
<value><password></value>
</parameter>
<parameter>
<name>maxActive</name>
<value>20</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>10</value>
</parameter>
<parameter>
<name>poolPreparedStatements</name>
<value>true</value>
</parameter>
</ResourceParams>
</DefaultContext>

*******
web.xml
*******
<resource-ref>
<description>DataSource Reference</description>
<res-ref-name>jdbc/postgres</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

************
Java bean file
************
public void doLogin() throws SQLException, NamingException {
Context ctx = new InitialContext();
if (ctx == null) throw new NamingException("No initial context");

DataSource ds = (DataSource) ctx.lookup("java:/comp/env/jdbc/postgres");
if (ds == null) throw new NamingException("No data source");

Connection conn = ds.getConnection();

if (conn == null) throw new SQLException("No connection");

try {
PreparedStatement passwordQuery = conn.prepareStatement(
"SELECT password from account WHERE username = ?");

passwordQuery.setString(1, this.userName);

ResultSet result = passwordQuery.executeQuery();

if (!result.next()) return;
String storedPassword = result.getString("password");
loggedIn = this.myPassword.equals(storedPassword.trim());
}
finally {
conn.close();
}
}

***************************************
JAR files in $CATALINA_HOME/common/lib
***************************************
ant-launcher.jar
ant.jar
commons-collections-3.1.jar
commons-dbcp-1.2.1.jar
commons-el.jar
commons-pool-1.2.jar
jasper-compiler.jar
jasper-runtime.jar
jsp-api.jar
naming-common.jar
naming-factory.jar
naming-java.jar
naming-resources.jar
postgresql-8.1-407.jdbc3.jar
servlet-api.jar
tools.jar

**********************************
JAR files in application library
**********************************
commons-beanutils.jar
commons-collections.jar
commons-digester.jar
commons-lang.jar
commons-logging.jar
jsf-api.jar
jsf-impl.jar
jsfExt.0.8.1.jar
jstl.jar
standard.jar
struts-el.jar
struts.jar




All times are GMT -4. The time now is 04:04 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.