Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3804834
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:34:54+00:00 2026-05-19T14:34:54+00:00

I have spent 2 days trying to figure out why my servlet does not

  • 0

I have spent 2 days trying to figure out why my servlet does not connect to the MySQL database.

I have MySQL installed and working properly and Eclipse.

Whenever I try to establish a connection, I get a ClassNotFoundException for the com.mysql.jdbc.Driver, which is actually properly imported. The connector I’m using is the mysql-connector-java5.1.14 added properly as an external jar, so everything seems fine. Here’s my code:

 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

  String dbUrl="jdbc:mysql://localhost:3306/test";
  String username="root";
  String password="";



  try {
   Class.forName("com.mysql.jdbc.Driver").newInstance();
   conn=DriverManager.getConnection(dbUrl);
   System.out.println("Connected!");

  } catch (SQLException e) {
   e.printStackTrace();
   System.out.println("not connected");

  } catch(ClassNotFoundException x){
   x.printStackTrace();

  } catch(Exception e){

   e.printStackTrace();
  }


 }

Here’s part of the stack trace:

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
 at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:375)
 at java.lang.Class.forName0(Native Method)
 at java.lang.Class.forName(Class.java:164)

I’m following the connection steps from a published Java book. In forums and tutorials, I just see the same code, cannot figure out why that exception is thrown.

On a normal application which does not run on the server the exception isn’t thrown and the connection (in the exact same way) its successful.

Do you have any advice?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T14:34:55+00:00Added an answer on May 19, 2026 at 2:34 pm

    Two possible solutions:

    1) When you create the WAR, is that driver inside? You can unzip it (rename the .war file to .zip and just take a look — it should be under /WEB-INF/lib.) Eclipse might not be exporting it to the WAR.

    2) Did you put it into the Tomcat lib directory, if you’re using Tomcat? If not, which servlet container are you deploying into?

    One thing I’ve noticed is that sometimes, Java doesn’t like there being spaces to a class. You should be able to avoid it by including it in either of the two solutions so it becomes a relative path, but you can try to eliminate the space and see if it helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have spent days trying to figure this out to no avail. I have
I've spent the last 2 days trying to figure this out, basically I have
I have spent a couple days trying to figure out why my asp master
I have spent multiple hours trying to figure out how to pass multiple parameters
I've spent several days trying to figure out what is wrong with my android
I spent 4 full days trying everything I can to figure out the memory
I've spent days trying to figure this out and I give up. I am
Okay I have spent the last 2 days trying to sort this one out.
I have spent days on this trying out all the JSON libraries including the
Ok, I never post on here until I've spent days trying to figure it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.