Hi all,
I saved my connector/j rar file into this location C:\ ... \Java\jre6\lib\ext

and i am using this code in the JSP :
Class.forName("com.mysql.jdbc.Driver").newInstance();

I am getting below driver error message. Somebody please help me out.

javax.servlet.ServletException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

Dani AI

Generated

Short, practical explanation and fix checklist tied to the existing posts.

As pointed out, the MySQL connector JAR must be visible to the same classloader that the container or your app uses — putting the driver into Tomcat’s shared/common lib (or into a webapp’s WEB-INF/lib if it’s app‑specific) is the usual resolution for driver ClassNotFound errors. Also confirm the Connector/J release matches the driver class name your configuration expects; the Connector/J manual documents the supported installs and classnames. Tomcat class loader HOW‑TO. (tomcat.apache.org)

The “Unable to load class for JSP / java.lang.ClassNotFoundException: org.apache.jsp.Demo1_jsp” is normally a symptom that the JSP did not successfully compile to a servlet class (not a missing hand‑written class). Typical root causes include JSP compile errors (syntax, bad includes), a corrupted or out‑of‑date work cache, file‑permission or disk‑space problems, or accidentally bundling server APIs in the WAR. Check the full Jasper/catalina logs — the real compile error will be shown there. (stackoverflow.com)

Practical checklist (apply in order):

  1. Stop Tomcat.
  2. Delete the app’s generated JSP cache (the <CATALINA_BASE>/work folder) and ensure Tomcat can write to its work/log directories (fix ownership/permissions).
  3. Confirm no servlet/JSP API JARs are packaged inside the WAR (use “provided” scope in builds).
  4. Put a single, correct Connector/J JAR either in the webapp’s WEB‑INF/lib (app only) or Tomcat’s lib (container/global); remove duplicate copies and avoid relying on JVM ext folders.
  5. Restart Tomcat and tail catalina.out to watch for JSP compilation errors and fix the first error seen.

Example quick commands (Linux):

# stop Tomcat (system-specific)
rm -rf $CATALINA_BASE/work/*
chown -R tomcat:tomcat $CATALINA_BASE
tail -f $CATALINA_BASE/logs/catalina.out

Deleting the work directory and fixing permissions often resolves the “Unable to load class for JSP” symptom; the logs then show the real compilation error to correct. (support.atlassian.com)

If the logs show a JSP compilation exception or a missing include, resolve that JSP error first — the container will then regenerate the servlet class in the work folder on the next request. (tomcat.apache.org)

Recommended Answers

All 2 Replies

Hi Thanks for the quick response. I copied the rar file into $CATALINA_HOME/common/lib and there was no driver error. But now i am facing a new problem. My JSP name is Demo.jsp, its showing "org.apache.jasper.JasperException: Unable to load class for JSP
" and "java.lang.ClassNotFoundException: org.apache.jsp.Demo1_jsp". For this I remember, we need to make some changes in the xml file present in WEB-INF. So that the class file must go and sit in the src folder. I am still confused.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.