reset password
Author Message
abess
Posts: 26
Posted 17:23 May 26, 2011 |

This code keeps throwing an exception...

 

 public void init( ServletConfig config ) throws ServletException
    {
        super.init( config );
 
        try
        {
            Class.forName( "com.mysql.jdbc.Driver" );
        }
        catch( ClassNotFoundException e )
        {
            throw new ServletException( e );
        }
    }
javax.servlet.ServletException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
	cs320.servlet.HelloJDBC.init(HelloJDBC.java:38)
	org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:498)
	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
	org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:394)
	org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
	org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
	org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
	org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
	java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
	java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	java.lang.Thread.run(Unknown Source)

 

root cause

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
	org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
	org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
	java.lang.Class.forName0(Native Method)
	java.lang.Class.forName(Unknown Source)
	cs320.servlet.HelloJDBC.init(HelloJDBC.java:34)
	org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:498)
	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
	org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:394)
	org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
	org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
	org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
	org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
	java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
	java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	java.lang.Thread.run(Unknown Source)


I keep trying to find a way around it, i reinstalled the mysql drivers, changed the sql code, moved things around... nothing seems to work.

Is there any way to fix this?

Last edited by abess at 17:25 May 26, 2011.
cysun
Posts: 2935
Posted 17:30 May 26, 2011 |

When you say you reinstalled the MySQL driver, what exact did yo do? If you didn't put the jar file in the Tomcat lib folder when you created the server runtime in Eclipse, you need to create a new server runtime after you put the jar file there.

Or you can just put the jar file under WebContent/WEB-INF/lib of the project folder.

Last edited by cysun at 17:30 May 26, 2011.
abess
Posts: 26
Posted 17:31 May 26, 2011 |

How do i create a new server runtime? I dont remember, I put it in at the begining of the quarter...

Last edited by abess at 17:32 May 26, 2011.
cbort
Posts: 95
Posted 18:31 May 26, 2011 |

In Eclipse on the tabs at the bottom there is a server tab... If you already have a server and it is not working double click and you can edit it. If it is not there in the servers tab right click and go to New->server
Another way to fix it is to create a new dynamic web project and just copy all of the source code, jsps etc to it. I used to be having this problem on a fairly regular basis.

I believe that when I had this problem it was because I would switch between two different computers with the project. I eventually created separate projects for each computer and have not encountered the problem since.

abess
Posts: 26
Posted 19:13 May 26, 2011 |

None of those solutions worked.  I found the problem though, i accidentally put the jar files into the bin folder instead of the lib.

Last edited by abess at 19:14 May 26, 2011.