Exception :-
Please provide me a solution to following error when i try to run Java file which has connections to MYSQL database.
[javax.servlet.ServletException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver] with root cause
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:126)
at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.apache.jsp.login_jsp._jspService(login_jsp.java:62)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
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:541)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:383)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:288)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Hi,just add mysql-connector-java-5.1.20-bin.jar to your build path. It works for me.
ReplyDeleteThanks for response. But it is not working for me.
ReplyDeleteI found a solution to same. That rather than adding mysql-connector-java-5.1.20-bin (jar) file to java build path. I have explicitly added mysql-connector-java-5.1.20-bin.jar to WEB-INF\lib folder. It is working fine now.
ReplyDeletethanks..it really worked for me
DeleteThank you
DeletePiyush Mundada Thank you . your solution is very much correct. It worked for me.
ReplyDeleteThis comment has been removed by the author.
ReplyDeletebt it's nt working for me still shoes class nt found
ReplyDeletei hav added jar file to both places still gives error clas not found
ReplyDeleteCan you please post your class ?
Deletepiyush your concept is working fine.
Deletepiyush your concept is working fine.
DeleteHi,
ReplyDeleteI tried everything - from adding JAR file to WEB-INF/lib to adding it to Window>Preferences>Java>Classpath Variables. Still im getting java.lang.ClassNotFoundException and that huge list of error:
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:126)
at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.apache.jsp.NewFile_jsp._jspService(NewFile_jsp.java:65)....
My piece of scriplet is:
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%
System.out.println("-------- MySQL JDBC Connection Testing ------------");
try
{
Class.forName("com.mysql.jdbc.driver");
}
catch (ClassNotFoundException e)
{
//System.out.println("Where is your MySQL JDBC Driver?");
PrintWriter pw = new PrintWriter(System.out, true);
pw.println("Driver Connection Failed, yahoo!");
e.printStackTrace();
}
System.out.println("MySQL JDBC Driver Registered!");
Connection connection = null;
%>
Sorry, i got it running now.
DeleteI used:
Class.forName("com.mysql.jdbc.driver");
instead of
Class.forName("com.mysql.jdbc.Driver");// Capital D
Thanks
Happy to hear that...☺
DeleteI tried all the solutions..it still shows " java.lang.ClassNotFoundException: com.mysql.jdbc.Driver" can u please help?
ReplyDeleteCan you please post your class and exact issue log.
DeleteBy keeping WEB-INF/lib/mysql-connector-java-5.1.20-bin.jar like this it works...
ReplyDeleteThank you.My Problem is also solved because of your huge discussion on ClassNotFoundException.
ReplyDeleteReally Thank u again..
hi
ReplyDeletei am tried to running the program but is same isuess above mention...javax.servlet.ServletException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver this type error showing in my program....
i am also add the mysql-connector-java-5.1.5-bin but it is not working
ReplyDeleteCan you please post your class and exact issue log.
Deleteya i also have same problem.
ReplyDeletei add connector file in that direcotry,but yet it not working....
can u give me solution on this pls
Can you please post your class and exact issue log so that I can provide exact solution on same
Deletei also have same problem.i do all steps that u tell above, but yet it not working....
ReplyDeletecan u give me solution on this pls
my script is
Delete<%@ page import ="java.sql.*" %>
<%@ page import="java.io.*" %>
<%
String userid = request.getParameter("uname");
String pwd = request.getParameter("pass");
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/db", "root", "123");
Statement st = con.createStatement();
ResultSet rs;
rs = st.executeQuery("select * from members where uname='" + userid + "' and pass='" + pwd + "'");
if (rs.next()) {
session.setAttribute("userid", userid);
out.println("welcome " + userid);
out.println("Log out");
response.sendRedirect("success.jsp");
} else {
out.println("Invalid password try again");
}
%>
did you add mysql-connector-java-5.1.20-bin (jar) file to java build path ? Rather add explicitly mysql-connector-java-5.1.20-bin.jar to WEB-INF\lib folder. If still issue persist, then please revert back.
DeleteI have done all the steps,but it still shows ' java.lang.ClassNotFoundException: com.mysql.jdbc.Driver' exception.
ReplyDeleteThis comment has been removed by the author.
ReplyDelete