jsp - Besides Adding jar for JDBC,"java.lang.classnotfoundexception:com.mysql.jdbc.Driver " -
i have added jar file jdbc in build path project, still giving me exception javax.servlet.servletexception: java.lang.classnotfoundexception
: com.mysql.jdbc.driver"
i've added jar file in
project --> proeperties -->java bild path -->libraries -->add external library.
<html> <head><title>member details</title></head> <body> <h2>members details...!</h2> <table> <%@ page import="java.util.*" %> <%@ page import="java.sql.sqlexception" %> <%@ page import="javax.sql.*;" %> <% java.sql.connection con; java.sql.statement s; java.sql.resultset rs; java.sql.preparedstatement pst; con=null; s=null; pst=null; rs=null; // remember change next line own environment string url= "jdbc:mysql://localhost:3306/employees"; string id= "root"; string pass = "admin"; try{ class.forname("com.mysql.jdbc.driver"); con = java.sql.drivermanager.getconnection(url, id, pass); }catch(sqlexception e) { system.out.println("connection failed! check output console"); e.printstacktrace(); return; } string sql = "select id, age, first, last employee"; try{ s = con.createstatement(); rs = s.executequery(sql); %> <tr> <th>employee id</th> <th>employee age</th> <th>first name</th> <th>last name</th> </tr> <% while( rs.next() ){ %><tr> <td><%= rs.getstring("id") %></td> <td><%= rs.getstring("age") %></td> <td><%= rs.getstring("first") %></td> <td><%= rs.getstring("last") %></td> </tr> </table> <% } %> <% }catch(exception e){ e.printstacktrace(); } finally{ if(rs!=null) rs.close(); if(s!=null) s.close(); if(con!=null) con.close(); } %> </body> </html>
exception stacktrace:
org.apache.jasper.jasperexception: javax.servlet.servletexception: java.lang.classnotfoundexception: com.mysql.jdbc.driver org.apache.jasper.servlet.jspservletwrapper.handlejspexception (jspservletwrapper.java:549) org.apache.jasper.servlet.jspservletwrapper.service(jspservletwrapper.java:455) org.apache.jasper.servlet.jspservlet.servicejspfile(jspservlet.java:390) org.apache.jasper.servlet.jspservlet.service(jspservlet.java:334) javax.servlet.http.httpservlet.service(httpservlet.java:728) org.apache.struts2.dispatcher.ng.filter.strutsprepareandexecutefilter.dofilter(strutsprepareandexecutefilter.java:88)
root cause:
javax.servlet.servletexception: java.lang.classnotfoundexception: com.mysql.jdbc.driver org.apache.jasper.runtime.pagecontextimpl.dohandlepageexception(pagecontextimpl.java:912) org.apache.jasper.runtime.pagecontextimpl.handlepageexception(pagecontextimpl.java:841) org.apache.jsp.members_jsp._jspservice(members_jsp.java:164) org.apache.jasper.runtime.httpjspbase.service(httpjspbase.java:70) javax.servlet.http.httpservlet.service(httpservlet.java:728) org.apache.jasper.servlet.jspservletwrapper.service(jspservletwrapper.java:432) org.apache.jasper.servlet.jspservlet.servicejspfile(jspservlet.java:390) org.apache.jasper.servlet.jspservlet.service(jspservlet.java:334) javax.servlet.http.httpservlet.service(httpservlet.java:728) org.apache.struts2.dispatcher.ng.filter.strutsprepareandexecutefilter.dofilter(strutsprepareandexecutefilter.java:88)
root cause
java.lang.classnotfoundexception: com.mysql.jdbc.driver org.apache.catalina.loader.webappclassloader.loadclass(webappclassloader.java:1714) org.apache.catalina.loader.webappclassloader.loadclass(webappclassloader.java:1559) org.apache.jasper.servlet.jasperloader.loadclass(jasperloader.java:126) org.apache.jasper.servlet.jasperloader.loadclass(jasperloader.java:63) java.lang.class.forname0(native method) java.lang.class.forname(unknown source) org.apache.jsp.members_jsp._jspservice(members_jsp.java:94) org.apache.jasper.runtime.httpjspbase.service(httpjspbase.java:70) javax.servlet.http.httpservlet.service(httpservlet.java:728) org.apache.jasper.servlet.jspservletwrapper.service(jspservletwrapper.java:432) org.apache.jasper.servlet.jspservlet.servicejspfile(jspservlet.java:390) org.apache.jasper.servlet.jspservlet.service(jspservlet.java:334) javax.servlet.http.httpservlet.service(httpservlet.java:728) org.apache.struts2.dispatcher.ng.filter.strutsprepareandexecutefilter.dofilter(strutsprepareandexecutefilter.java:88)
you need jdbc driver @ runtime, not @ build time. jar should not added tho build path of eclipse project. should dropped inside webcontent/web-inf/lib
, automatically add build path , set of jars must deployed libraries of webapp.
Comments
Post a Comment