Hello, I am developing a JSP-based web application that uses database (MySQL) to preserve data. I am using a datasource (javax.sql.DataSource) as a global resource and a datasource realm (org.apache.catalina.realm.DataSourceRealm) as a realm for authenticating the users of my web application.
I encountered the following problem when I changed the plain old JDBC-connection (java.sql.Connection) of my web application, obtained from a call to DriverManager, to a DBCP-datasource obtained from a JNDI-lookup. I have browsed through multiple mailing list archives, but have not found any solutions to this. The problem is that when I try to open the connection by calling method dataSource.getConnection() it throws a java.sql.SQLException stating "Cannot load JDBC driver class 'null'". The weird part is, that the form-based authentication that uses the same datasource works fine! So it seems that only the classes in my web application cannot find the appropriate JDBC-driver and thus does not work. I have included the .jar-file in $CATALINA_HOME/common/lib. Can anyone give me a good explanation why this happens, and solve my problem? Server.xml (important parts): <GlobalNamingResources> <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"/> <ResourceParams name="jdbc/TestDB"> <parameter> <name>factory</name> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value> </parameter> <parameter> <name>maxActive</name> <value>100</value> </parameter> <parameter> <name>maxIdle</name> <value>30</value> </parameter> <parameter> <name>maxWait</name> <value>10000</value> </parameter> <parameter> <name>username</name> <value>userx</value> </parameter> <parameter> <name>password</name> <value>passx</value> </parameter> <parameter> <name>driverClassName</name> <value>com.mysql.jdbc.Driver</value> </parameter> <parameter> <name>url</name> <value>jdbc:mysql://localhost/TestDB?autoReconnect=true</value> </parameter> </ResourceParams> </GlobalNamingResources> <Service...> <Engine...> <Realm className="org.apache.catalina.realm.DataSourceRealm" debug="99" dataSourceName="jdbc/TestDB" userTable="UserTBL" userNameCol="userid" userCredCol="pass" userRoleTable="RoleTBL" roleNameCol="role"/> </Engine> </Service> Web.xml (important parts): <resource-ref> <res-ref-name>jdbc/TestDB</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> Web application code: Context ctx = new InitialContext(); dataSource = (DataSource)ctx.lookup("java:comp/env/jdbc/TestDB"); connection = dataSource.getConnection(); //this throws the Exception //This used to work //Class.forName ("com.mysql.jdbc.Driver").newInstance (); //connection = DriverManager.getConnection("jdbc:mysql://localhost/" + database, "userx", "passx"); Exception: java.sql.SQLException: Cannot load JDBC driver class 'null' at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:529) at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:312) at package.BaseDAO.openConnection(Unknown Source) at package.OwnDAO.ownMethod(Unknown Source) at org.apache.jsp.onw_jsp._jspService(own_jsp.java:76) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193) --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]