java - Configure Tomcat so that I can connect a JSP page to MySQL -
i need connect mysql database jsp page using drivermanager.getconnection()
method. have placed mysql connector-j jar file in tomcat lib. have run same code normal java application , works, makes me think there issue tomcat. getting many exceptions, first 1 being classnotfoundexception
, followd many jasperexception
.
could tell me steps need follow in configuring servlet interact mysql jsp page?
update: have tried putting in lib folder of tomcat install root /web-inf/lib
, problem persists. jar file name mysql-connector-java-5.1.13-bin.jar
. right one?
here exception getting
java.lang.classnotfoundexception: com.mysql.jdbc.driver @ org.apache.catalina.loader.webappclassloader.loadclass(webappclassloader.java:1645) @ org.apache.catalina.loader.webappclassloader.loadclass(webappclassloader.java:1491) @ org.apache.jasper.servlet.jasperloader.loadclass(jasperloader.java:128) @ org.apache.jasper.servlet.jasperloader.loadclass(jasperloader.java:66) @ java.lang.class.forname0(native method) @ java.lang.class.forname(class.java:169) @ org.apache.jsp.index_jsp._jspservice(index_jsp.java:75) @ org.apache.jasper.runtime.httpjspbase.service(httpjspbase.java:70) @ javax.servlet.http.httpservlet.service(httpservlet.java:717) @ org.apache.jasper.servlet.jspservletwrapper.service(jspservletwrapper.java:377) @ org.apache.jasper.servlet.jspservlet.servicejspfile(jspservlet.java:313) @ org.apache.jasper.servlet.jspservlet.service(jspservlet.java:260) @ javax.servlet.http.httpservlet.service(httpservlet.java:717) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:290) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:233) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:191) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:127) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:102) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:109) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:298) @ org.apache.coyote.http11.http11processor.process(http11processor.java:857) @ org.apache.coyote.http11.http11protocol$http11connectionhandler.process(http11protocol.java:588) @ org.apache.tomcat.util.net.jioendpoint$worker.run(jioendpoint.java:489) @ java.lang.thread.run(thread.java:619)
assuming classnotfoundexception
referring jdbc driver com.mysql.jdbc.driver
, means connector-j jar file not been placed in classpath properly.
in fact, placing in tomcat's /lib
folder should fix problem. since seem have done this, can mean either didn't put right jar file there @ all, or /lib
folder you're talking wrong folder. in case of tomcat 6.0 or newer, should /lib
folder inside tomcat installation folder (it should exist, shouldn't create 1 yourself!). in case of tomcat 5.5 or older, should /shared/lib
folder inside tomcat installation folder (again, should there).
an alternative put jar file in /web-inf/lib
folder of webapplication. disadvantage jar file end in classpath of webapp used. other webapps in same servletcontainer have duplicate jar file. also, won't able utilize tomcat-provided connection pooling facilities improve connecting performance.
update: per stacktrace:
java.lang.classnotfoundexception: com.mysql.jdbc.driver
the classname wrong. java case sensitive. should com.mysql.jdbc.driver
.
Comments
Post a Comment