It's not a secret anymore!*
The moose likes JDBC and the fly likes Cannot load JDBC driver class 'com.mysql.jdbc.Driver' Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Cannot load JDBC driver class Watch "Cannot load JDBC driver class New topic
Author

Cannot load JDBC driver class 'com.mysql.jdbc.Driver'

Clinton Morrison
Greenhorn

Joined: Jun 28, 2007
Posts: 24
When I try to connect to http://localhost:8080/database/index.jsf I receive the following error Cannot load JDBC driver class 'com.mysql.jdbc.Driver'.

C:\Program Files\ExadelStudioPro-4.0.4a\tomcat\common\lib I have placed the mysql-connector-java-5.0.7.

In server.xml I have placed the following
<Context
docBase="database"
path="/database"
reloadable="true"
source="org.eclipse.jst.j2ee.server:database">
<Resource
auth="Container"
description="MyApp DataSource Reference"
name="jdbc/corejsf"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
password="newuser"
maxIdle="2"
maxWait="5000"
username="root"
url="jdbc:mysql://localhost/corejsf"
maxActive="4" />
</Context>

In the web.xml file

<resource-ref>
<res-ref-name>jdbc/corejsf</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

Any help would be grately appreciated!
Thanks
Clinton Morrison
Zein Nunna
Ranch Hand

Joined: Mar 31, 2005
Posts: 245
Could you please post more of the whole error message.

If you're using windows, go the following folder ...Apache Software Foundation\Tomcat 5.5\logs to get the error message.

Also if you're using MySQL & Tomcat you need to have the following jars in the lib folder,
Jakarta-Commons DBCP 1.0
Jakarta-Commons Collections 2.0
Jakarta-Commons Pool 1.0

See link for more details.
Clinton Morrison
Greenhorn

Joined: Jun 28, 2007
Posts: 24
Hi,
Sorry there was nothing in the log folder C:\ExadelStudioPro-4.0.4a\tomcat\logs. THe console did print the following error message. I am not sure if this helps.

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: javax.servlet.jsp.JspException: javax.faces.el.EvaluationException: Error getting property 'all' from bean of type com.corejsf.CustomerBean: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)


root cause

javax.servlet.ServletException: javax.servlet.jsp.JspException: javax.faces.el.EvaluationException: Error getting property 'all' from bean of type com.corejsf.CustomerBean: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:854)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
org.apache.jsp.index_jsp._jspService(index_jsp.java:83)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)


root cause

javax.faces.el.EvaluationException: javax.faces.el.EvaluationException: Error getting property 'all' from bean of type com.corejsf.CustomerBean: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
com.sun.faces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:206)
com.sun.faces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:154)
javax.faces.component.UIData.getValue(UIData.java:527)
javax.faces.component.UIData.getDataModel(UIData.java:856)
javax.faces.component.UIData.setRowIndex(UIData.java:379)
com.sun.faces.renderkit.html_basic.TableRenderer.encodeBegin(TableRenderer.java:65)
javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:683)
javax.faces.component.UIData.encodeBegin(UIData.java:681)
javax.faces.webapp.UIComponentTag.encodeBegin(UIComponentTag.java:591)
javax.faces.webapp.UIComponentTag.doEndTag(UIComponentTag.java:543)
com.sun.faces.taglib.html_basic.DataTableTag.doEndTag(DataTableTag.java:491)
org.apache.jsp.index_jsp._jspx_meth_h_dataTable_0(index_jsp.java:247)
org.apache.jsp.index_jsp._jspx_meth_h_form_0(index_jsp.java:192)
org.apache.jsp.index_jsp._jspx_meth_f_view_0(index_jsp.java:122)
org.apache.jsp.index_jsp._jspService(index_jsp.java:74)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.


--------------------------------------------------------------------------------

Apache Tomcat/5.5.17
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
Maybe the following link will help

Cannot load JDBC-driver

I had the same problem and the following solution helped me

While configuring the datasource, the driver jar (mysql connector/j in this case) should be placed only in the TOMCAT_HOME/common/lib directory and nowhere else. If you have the same jar in WEB-INF/lib or the jre extension directory, this problem is encountered. The solution is to remove the jars from all other places and keep it only in the common/lib directory of Tomcat.

Refer to the Tomcat documentation on how to configure the datasource. This has been mentioned as a note.


Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
Nirlep Patel
Greenhorn

Joined: Jul 29, 2007
Posts: 7
i assume that you are using NetBeans IDE 5.5

put your mysql connector to

C:\Program Files\netbeans-5.5\enterprise3\apache-tomcat-5.5.17\common\lib directory.

in my it is working perfectly.


regards, nirlep
discuss.teaching@gmail.com, http://www.learnclinux.com
Clinton Morrison
Greenhorn

Joined: Jun 28, 2007
Posts: 24
Presently I am using Eclipse 3.2. I searched my hardrive to ensure the driver was only installed in C:\Program Files\ExadelStudioPro-4.0.4a\tomcat\common\lib. IS there perhaps a different server I could use to run locally?

Thank you for the help.
Clinton
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
I use eclipse 3.2 and don't have a problem.

I think you should just try your connection code in textfile for making sure that you can connect and check if you have the right MySql-connector

MySql Connector
Santhosh Reddy
Greenhorn

Joined: Sep 25, 2006
Posts: 27
Make sure that you have mysqlconnector.jar in the libraries folder of your application explore your appliation,in src find libraries and in libraries find tomcat and in tomcat find your jar,if you cant see jar file,please keep one over there.
[ August 05, 2007: Message edited by: Santhosh Reddy ]
Clinton Morrison
Greenhorn

Joined: Jun 28, 2007
Posts: 24
I reinstalled eclipse and tomcat and followed the instructions here and it worked. Thank-you for all the help it was much appreciated.

Clinton
Sathish Thiruppathy
Greenhorn

Joined: Feb 11, 2010
Posts: 3
By placing mysql-connector jar under Tomcat common lib directory will solve connection exception.




Thanks,
www.vSellOnline.com
Sandeep Kumar Arya
Greenhorn

Joined: Jul 29, 2011
Posts: 2
I have created a servlet in which during connecting to mysql .
I have got a problem in communication Excepiton....



com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:



import java.sql.*;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class EnterDataDB
*/
@WebServlet("/EnterDataDB")
public class servlets extends HttpServlet {
private static final long serialVersionUID = 1L;



protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("****initilizing the class uploading process************");

try{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("****class has successfully loaded******");

String url="jdbc:mysql://localhost/books?user=root&password=12345 ";
Connection conn = DriverManager.getConnection(url);

PreparedStatement smt= conn.prepareStatement("select * from books_detals");

ResultSet rs= smt.executeQuery();
while(rs.next()){
System.out.println(" "+rs.getString(1)+" " +rs.getString(2));
}

}catch(Exception ex){
ex.printStackTrace();
}



}


}


** BEGIN NESTED EXCEPTION **

java.net.ConnectException
MESSAGE: Connection refused: connect

STACKTRACE:

java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.<init>(Socket.java:375)
at java.net.Socket.<init>(Socket.java:218)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:271)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2771)
at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:207)
at servlets.doGet(servlets.java:29)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:851)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:278)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)


** END NESTED EXCEPTION **



Last packet sent to the server was 0 ms ago.
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2847)
at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:207)
at servlets.doGet(servlets.java:29)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:851)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:278)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
mulai vendan
Greenhorn

Joined: Mar 04, 2013
Posts: 1
thank you
Remko Strating
 
 
subject: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'