tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alan Chandler <a...@chandlerfamily.org.uk>
Subject Struggling with basic database connection
Date Sat, 23 Sep 2006 08:24:07 GMT
I am struggling to figure out why my Tomcat installation is failing to allow 
me to connect my java web application to a database.  I am looking for ideas 
as to how to find out what is wrong.  I have (what I think) is the same setup 
on another machine and it works fine.  The only difference between these is 
that the working one in tomcat 5.0 and this machine is tomcat 5.5 (although I 
am just about and try with a 5.0 setup).

I am trying with this simple piece of code - plucked from the tomcat docs.

		Context initCtx;
		try {
			initCtx = new InitialContext();
			Context envCtx = (Context) initCtx.lookup("java:comp/env");
			DataSource ds = (DataSource) envCtx.lookup("jdbc/akcmoney");
			Connection conn = ds.getConnection();		
		} catch (Exception e1) {
			e1.printStackTrace();
		}

and with debug, I can see that initCtX, envCtx and ds all are assigned non 
null values, but the ds.getConnection() results in the following.

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC
driver of class '' for connect URL 'null'

I have the postgresql jdbc driver jar in $CATALINA.BASE/common/lib

Server.xml contains

     <Context docBase="akcmoney" path="/akcmoney" reloadable="true"
source="org.eclipse.jst.j2ee.server:akcmoney">
          <Resource auth="Container" name="jdbc/akcmoney"
type="javax.sql.DataSource"/>
            <ResourceParams name="jdbc/akcmoney">
             <parameter>
              <name>factory</name>
              <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
             </parameter>
             <parameter>
              <name>driverClassName</name>
              <value>org.postgresql.Driver</value>
             </parameter>
             <parameter>
              <name>url</name>
              <value>jdbc:postgresql://127.0.0.1:5432/akcmoney</value>
             </parameter>
             <parameter>
              <name>username</name>
              <value>tomcat4</value>
             </parameter>
             <parameter>
             <name>password</name>
              <value>xxxxxxx</value>
             </parameter>
             <parameter>
              <name>maxActive</name>
              <value>20</value>
             </parameter>
             <parameter>
              <name>maxIdle</name>
              <value>10</value>
             </parameter>
             <parameter>
              <name>maxWait</name>
              <value>-1</value>
             </parameter>
            </ResourceParams> 
      
      
     </Context>

my WEB-INF/web.xml contains this reference.

	<resource-ref>
 		<description>AKCMoney Database</description>
 		<res-ref-name>jdbc/akcmoney</res-ref-name>
 		<res-type>javax.sql.DataSource</res-type>
 		<res-auth>Container</res-auth>
 		<res-sharing-scope>Shareable</res-sharing-scope>
	</resource-ref>

Anyone any ideas where I am going wrong, or how to look at the contents of the 
nitCtX, envCtx and ds variables in the above code snippet to understand how 
far I have got


-- 
Alan Chandler
http://www.chandlerfamily.org.uk


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message