Hello, I have been trying to get a db2 connection using Tomcat 4.1.11 using the HOW-TO docs at http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html. I get the following error:
Cannot create JDBC driver of class 'COM.ibm.db2.jdbc.app.DB2Driver' for connect URL 'jdbc:db2:sample' I am able to get the DataSource but can't get a connection. Has anyone had experience with this error? I am using the sample db that comes with DB2. I can also use the standalone java app availble on the IBM site to test the connection and I can connect fine from the standalone app. I am including the appropriate files. The changes I made to server.xml ================================ <Context path="/DBTest" docBase="DBTest" debug="0" reloadable="true" crossContext="true"> <Resource name="jdbc/sample" auth="SERVLET" type="javax.sql.DataSource" description="DB2 TestDB"> </Resource> <ResourceParams name="jdbc/sample"> <parameter> <name>factory</name> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value> </parameter> <parameter> <name>maxActive</name> <value>10</value> </parameter> <parameter> <name>maxIdle</name> <value>1</value> </parameter> <parameter> <name>maxWait</name> <value>10000</value> </parameter> <parameter> <name>username</name> <value>user1</value> </parameter> <parameter> <name>password</name> <value>password1</value> </parameter> <parameter> <name>driverClassName</name> <value>COM.ibm.db2.jdbc.app.DB2Driver</value> </parameter> <parameter> <name>url</name> <value>jdbc:db2:sample</value> </parameter> </ResourceParams> </Context> web.xml file ============== <?xml version="1.0" encoding="ISO-8859-1"?> <!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> <description>MySQL Test App</description> <resource-ref> <description>DB Connection</description> <res-ref-name>jdbc/sample</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>SERVLET</res-auth> </resource-ref> </web-app> Servlet =========== package foo; import javax.naming.*; import javax.sql.*; import java.sql.*; public class DBTest { String foo = "No connection"; String bar = "No connection"; int errorCode = -47; StringBuffer message = new StringBuffer(); public void init() { try{ Context ctx = new InitialContext(); foo = "Context worked."; if (ctx == null ) throw new Exception("Boom - No Context"); DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/sample"); if (ds != null) { foo = "DataSource worked real good! "; // servlet fails here! Connection conn = ds.getConnection(); if (conn != null) { foo = "Got Connection "+conn.toString(); Statement stmt = conn.createStatement(); ResultSet rst = stmt.executeQuery("SELECT * from employee"); while(rst.next()) { foo=rst.getString(1); bar=rst.getString(2); } conn.close(); } } } catch(SQLException sql) { sql.printStackTrace(); errorCode = sql.getErrorCode(); message.append(sql.getMessage()); } catch(Exception e) { e.printStackTrace(); message.append(e.getMessage()); } } public String getFoo() { return foo; } public String getBar() { return bar; } public String getMessage() { return message.toString(); } public int getErrorCode() { return errorCode; } jsp file ========== <html> <head> <title>DB Test</title> </head> <body> <% foo.DBTest tst = new foo.DBTest(); tst.init(); %> <h2>Results</h2> Foo: <%= tst.getFoo() %><br> Bar: <%= tst.getBar() %><br> Message: <%= tst.getMessage() %><br> Error Code: <%= tst.getErrorCode() %> </body> </html> thanks, saulj -- To unsubscribe, e-mail: <mailto:tomcat-user-unsubscribe@;jakarta.apache.org> For additional commands, e-mail: <mailto:tomcat-user-help@;jakarta.apache.org>