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 7090271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:01:45+00:00 2026-05-28T08:01:45+00:00

According to this tutorial , calling Class.forName isn’t needed anymore with JDBC 4.0+ drivers.

  • 0

According to this tutorial, calling Class.forName isn’t needed anymore with JDBC 4.0+ drivers. I successfully followed the method in the example (just calling DriverManager.getConnection) for a stand-alone program using MySQL, but when I tried to connect to the exact same database from a class that was part of a web app running on Tomcat 7, it wouldn’t work; instead I got a No suitable driver found exception.

The mysql-connector-java-5.1.18-bin.jar file was in tomcat\webapps\DatabaseProject\WEB-INF\lib, I triple checked, but it wasn’t working, so I started trying things. I added a call to Class.forName and it worked. That was the only thing that changed.

Anyway my question is, does anybody know why this worked or what was going on here? My only theory is that I also have hsqldb.jar in tomcat\lib for another project and maybe somehow the drivers got confused? But I was under the impression that DriverManager is supposed to be able to tell automatically which driver to use, so that’s not supposed to be an issue… Anyway if someone could enlighten me as to what’s going on here, I’d really appreciate it.

  • 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-28T08:01:45+00:00Added an answer on May 28, 2026 at 8:01 am

    JDBC4 drivers include a file:

    META-INF/services/java.sql.Driver

    in the jar which uses the ServiceProvider mechanism to register the Driver implementation with the JVM (see javadocs for java.util.ServiceLoader). That’s why Class.forName is no longer necessary.

    My guess is that this is a class loader issue. The ServiceLoader javadoc mentions that:

    The provider must be accessible from the same class loader that was
    initially queried to locate the configuration file; note that this is
    not necessarily the class loader from which the file was actually
    loaded.

    I would try putting your driver in the tomcat\lib directory rather than your web app directory to see if that makes a difference (different class loader?).

    If you launch your web app through an ide and set a breakpoint, once you hit the breakpoint, you can use the “evaluate expression” feature to execute: ServiceLoader.load(Driver.class). This will give you a ServiceLoader class which you can peek into to see which Drivers are registered. You can check if the mysql driver is there, where in the list it is, etc, which might help in figuring out the behaviour here.

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

Sidebar

Related Questions

I was trying to validate an XML signature. The validation according to this tutorial
According to this tutorial , the DatePicker control is definitely present in the Javascript
I just add gcal to my project according to this tutorial http://www.youtube.com/watch?v=it_9H0GxRNI but 12
I have trying to install nhibernate according this tutorial, but it doesn't say where
I am using this tutorial and I did all the steps according to it.
I've tried according to this tutorial but failed. I've got everything copied exactly as
I want to use maven integrated with eclipse to develop webapp according this tutorial:
I set up the environment according to this tutorial: http://opencv.willowgarage.com/wiki/VisualC%2B%2B_VS2010 However the picture they
I am trying to get a multilingual site up according to this tutorial: http://nuts-and-bolts-of-cakephp.com/2008/11/28/cakephp-url-based-language-switching-for-i18n-and-l10n-internationalization-and-localization/
I am playing around with HTML 5 apps according to this tutorial: http://sixrevisions.com/web-development/html5-iphone-app/ It's

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.