Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java Open Source > Apache Tomcat
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Apache Tomcat General discussion of the Apache Tomcat servlet container. For discussions specific to the Professional Apache Tomcat book, please see the book discussion forum for that book.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Apache Tomcat section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 31st, 2006, 01:31 PM
Registered User
 
Join Date: Oct 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble connecting MySQL to PHP nofences84 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 June 14th, 2007 11:21 PM
tomcat with postgreSQL alejo_torres BOOK: Professional Apache Tomcat 0 October 14th, 2005 09:15 AM
Connecting with database in postgresql using c# dotnetprogrammer VS.NET 2002/2003 1 April 29th, 2005 07:05 AM
Connecting and retrieving data from postgresql dat dotnetprogrammer VS.NET 2002/2003 0 February 19th, 2005 01:12 AM
Trouble with connecting two table with relationshi tycoon Dreamweaver (all versions) 1 December 26th, 2003 07:21 AM



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


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