Hello,
I'm trying to load the MySQL JDBC driver from a jar file that I have placed in c:\Tomcat-5.5\shared\lib\. Please note that Tomcat IS finding this file and the driver within it, and I can verify this by placing a
Class.forName("com.mysql.jdbc.Driver");
somewhere in my code and it will NOT throw any exceptions. And the driver jar file will be locked by Windows, which will tell me it is being used.
I have this in my webapp's META-INF/context.xml:
<Resource name="jdbc/DB" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="********" password="***"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/test"/>
and this in my WEB-INF/web.xml:
<listener>
<listener-class>
org.trainingforlife.elearning.webapp.listeners.ContextListener
</listener-class>
</listener>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/DB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
I have the following in one of the classes invoked from the above ContextListener classes contextInitialized() method (it is wrapped in a rethrowing try/catch block):
try {
ds = (DataSource) new InitialContext().lookup("java:comp/env/jdbc/DB");
db = ds.getConnection();
}
catch(....)
...
And here's the output that I get from Tomcat:
SEVERE: Cannot initialise core! Core(): Couldn't open connection to database. Received org.apache.tomcat.dbcp.dbcp.SQLNestedException exception with message 'Cannot load JDBC driver class 'com.mysql.jdbc.Driver''
org.trainingforlife.elearning.Core$Problem: Core(): Couldn't open connection to database. Received org.apache.tomcat.dbcp.dbcp.SQLNestedException exception with message 'Cannot load JDBC driver class 'com.mysql.jdbc.Driver''
at org.trainingforlife.elearning.Core.<init>(Core.java:77)
at org.trainingforlife.elearning.webapp.listeners.ContextListener.contextInitialized(ContextListener.java:17)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3637)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4073)
at org.apache.catalina.manager.ManagerServlet.start(ManagerServlet.java:1175)
at org.apache.catalina.manager.HTMLManagerServlet.start(HTMLManagerServlet.java:510)
at org.apache.catalina.manager.HTMLManagerServlet.doGet(HTMLManagerServlet.java:104)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:482)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:738)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Unknown Source)
14-Apr-2005 15:46:56 org.apache.catalina.core.ApplicationContext log
INFO: HTMLManager: list: Listing contexts for virtual host 'localhost'
Interestingly, as I said, if I do something like
Class.forName("com.mysql.jdbc.Driver");
in any part of my code, it does NOT throw an exception - i.e. the driver class is being found.
So, if that's not the problem, can anybody tell me what is?
Thanks,
Asfand Yar