Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem connecting Tomcat to Postgres in JSF application

Status
Not open for further replies.

raindogs

Programmer
Nov 23, 2005
27
US
Hello all,

I'm a bit new at JSF and Tomcat, and I'm havign some trouble connecting to a Postgres DB. I'm 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 runt he 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 applciation files below, any suggestions would be much appreciated.

*********
server.xml
*********
<!-- connection for PostgreSQL DB -->
<DefaultContext>
<Resource name="jdbc/postgres" auth="Container" type="javax.sql.DataSource" />
<ResourceParams name="jdbc/postgres">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</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();
}
}



 
Driver jar file is probably not in shared/lib or common/lib

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Thanks for the response. I think you're probably right that I'm missing a JAR file, but I'm not sure which one. Pasted below are the lists of jars from both the common/lib and the application library. Can anyone out there spot the missing piece?

---------------------------
<application>\WEB-INF\lib
---------------------------
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
postgresql-8.1-407.jdbc3.jar
standard.jar
struts-el.jar
struts.jar

---------------------------
<CATLINA 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
 
Another interesting development... I took the postgres connection jar out of both the local/lib and conf/lib directories and got exactly the same message. Clearly, this JAR file is either not being read or is not being accessed properly. Help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top