Java. SQL. SQLException: No suitable driver found for jdbc, nosuitabledriver

Source: Internet
Author: User

Java. SQL. SQLException: No suitable driver found for jdbc, nosuitabledriver

When I used some components a few days ago, I encountered this error: java. SQL. SQLException: No suitable driver found for jdbc: XXX. After that, I searched for a solution on the Internet. Why can this problem be solved? record it here:

I. Solutions for online search

No Suitable Driver Found For Jdbc _ My Solution

The solution in this article is to add the driver jar package on jre \ lib \ ext and solve the problem;

But the explanation is not what the author said. We need to put the jar package in an external jar package environment. The root cause is that the program did not load the driver jar package;

When the program does not load the driver package, it runs DriverManager. getConnection (url, usr, psd) and this error is reported:

No suitable driver found for jdbc: XXX

  

Class. forName () is missing here. When I place the driver package on jre \ lib \ ext according to the preceding solution, the problem can also be solved:

Obviously, the error "No suitable driver found for jdbc" is reported because the program does not load the driver jar package, even though the jar package is included in lib.

Ii. About the Class Loader

Information about the class loader on the Internet:

The tree-like delegation mechanism is used for class loading. By default, there are three class loaders:

1. Bootstrap Class Loader: Load jre/lib/rt. jar; at the root node of the tree

2. Extension Class Loader: Load jre/lib/ext/*. jar;

3. System Class Loader: load the jar or directory specified by classpath;

Their Loading Order is: first bootstrap loading, then extension loading, and finally system loading.

Load policy: the upstream delegation policy. classes to be loaded by the lower-level class loaders (L) are first loaded by the highest-level class loaders. If loading fails, classes are passed down, if the loader (L) cannot be loaded, an error is returned.

An article on JVM class loading mechanism;

In this article, Class. the forName () Class Loader is the caller's class loader. In short, you can solve the problem by loading the driver jar package, no matter where the jar package is loaded.

Iii. References

1. No Suitable Driver Found For Jdbc _ My Solutions

2. No suitable driver found for jdbc: XXX

3. What is the problem if Java puts the JAR file in the jre/lib/ext directory?

4. JVM class loading mechanism

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.