Java: No suitable driver found for jdbc: URL
DriverManager found no driver accepting the URL. Put the driver on the runtime classpath, match the URL prefix and handle split classloaders.

Introduction & Quick Summary
A service that connected fine from the IDE fails on the server at startup:
java.sql.SQLException: No suitable driver found for jdbc:mysql://db:3306/shop
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:702)Quick answer: DriverManager walked every registered driver and none of them claimed that URL. The driver JAR is missing from the runtime classpath, or it is loaded by a classloader that the calling code cannot see.
<!-- the driver must be a runtime dependency of the deployed artifact -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>9.1.0</version>
<scope>runtime</scope>
</dependency>Since JDBC 4.0 the driver registers itself from META-INF/services/java.sql.Driver when its JAR is on the classpath, so Class.forName("com.mysql.cj.jdbc.Driver") is no longer required — and adding it does not help when the JAR is absent. The missing piece is almost always packaging, not code.
Three distinct failures are often reported under this one complaint:
No suitable driver found for jdbc:...— no registeredDriveraccepts the URL.Failed to determine a suitable driver class— Spring Boot could not infer a driver from the URL, usually a missing dependency.No driver suitable for jdbc:...in a container — the driver is inside a nested JAR the loader cannot scan.
Core Mechanics, Signatures & Reproducible Setup
DriverManager iterates registeredDrivers, calls driver.acceptsURL(url) on each, and instantiates the first match. The service loader populates that list the first time DriverManager is used, from the classloader that initialized it.
import java.sql.*;
public class Probe {
public static void main(String[] args) throws Exception {
DriverManager.getDrivers().asIterator().forEachRemaining(d ->
System.out.println(d.getClass().getName() + " v" + d.getMajorVersion()));
try (Connection c = DriverManager.getConnection(
"jdbc:mysql://db:3306/shop", "app", "secret")) {
System.out.println("connected: " + c.getMetaData().getDatabaseProductName());
}
}
}Run it with the deployed artifact, not with the IDE classpath:
java -cp "app.jar:lib/*" Probe| Database | URL prefix | Driver class | Maven artifact |
|---|---|---|---|
| MySQL | jdbc:mysql:// | com.mysql.cj.jdbc.Driver | com.mysql:mysql-connector-j |
| PostgreSQL | jdbc:postgresql:// | org.postgresql.Driver | org.postgresql:postgresql |
| SQL Server | jdbc:sqlserver:// | com.microsoft.sqlserver.jdbc.SQLServerDriver | com.microsoft.sqlserver:mssql-jdbc |
| Oracle | jdbc:oracle:thin:@ | oracle.jdbc.OracleDriver | com.oracle.database.jdbc:ojdbc11 |
| H2 | jdbc:h2: | org.h2.Driver | com.h2database:h2 |
| MariaDB | jdbc:mariadb:// | org.mariadb.jdbc.Driver | org.mariadb.jdbc:mariadb-java-client |
Key Comparison Table
| Cause | Symptom detail | Confirming check | Fix |
|---|---|---|---|
| Driver JAR absent | list of drivers is empty or lacks it | DriverManager.getDrivers() | add a runtime dependency |
| URL prefix wrong | driver present, still no match | compare the URL with the table | correct the prefix |
provided or test scope | works in tests, fails in the JAR | inspect the built artifact | change scope to runtime |
| Split classloader | driver visible to server, not to the app | list drivers from app code | use the container datasource |
| Fat JAR without services merge | no drivers at all | jar tf app.jar for the services file | merge with ServicesResourceTransformer |
| Driver too old for URL options | match fails on new parameters | driver version against docs | upgrade the driver |
Messages that look related but are not:
| Message | Real cause | Where to look |
|---|---|---|
| Failed to determine a suitable driver class | Spring Boot cannot map URL to driver | spring.datasource.url and dependency |
| No suitable driver found | DriverManager has no match | classpath and URL |
| Communications link failure | driver connected, server unreachable | host, port, firewall |
| Public Key Retrieval is not allowed | MySQL auth over plain connection | allowPublicKeyRetrieval and TLS |
| Access denied for user | credentials | grants and user host |
Practical Edge Cases, Error Fixes & Deep Dive Code Examples
1. The URL prefix must match the driver
// MariaDB driver does not accept this prefix
DriverManager.getConnection("jdbc:mysql://db:3306/shop", user, pass);
// No suitable driver found
// either use the MariaDB prefix
DriverManager.getConnection("jdbc:mariadb://db:3306/shop", user, pass);
// or add the MySQL connectorThe reverse case is just as common: a jdbc:postgresql: URL with only the MySQL connector on the classpath. Compare the URL character by character; jdbc:postgres:// is a frequent typo that produces this exact exception. Store the URL and credentials in one configuration source rather than in several properties files, and compare environments with the env formatter when dev works and prod does not.
2. Packaging: scope, shading and nested JARs
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
</configuration>
</plugin>Without the services transformer, the shade plugin keeps the first META-INF/services/java.sql.Driver it finds and drops the rest, so a multi-database build registers only one driver. Spring Boot's repackaged JAR keeps nested JARs under BOOT-INF/lib; the driver loads normally there, but code that scans the classpath by file path does not see it.
jar tf target/app.jar | grep -E "services/java.sql.Driver|mysql-connector"
unzip -p target/app.jar META-INF/services/java.sql.Driver3. Application servers and split classloaders
Tomcat, WildFly and WebLogic give each web application its own classloader. A driver placed in the server's lib directory is visible to the server, and the app can use it, but DriverManager filters drivers by the caller's classloader when the caller is a web app. Two workable patterns:
// 1. register explicitly with the app's loader at startup
Class.forName("com.mysql.cj.jdbc.Driver", true, getClass().getClassLoader());
// 2. or let the container own the pool and inject a DataSource
@Resource(lookup = "java:comp/env/jdbc/shop")
private DataSource ds;The second is preferable in an app server: the container manages connections, and the application never touches DriverManager. The context.xml resource declares driverClassName and url once, and the app code asks for the JNDI name.
4. Spring Boot and the "failed to determine" message
spring:
datasource:
url: jdbc:postgresql://db:5432/shop
username: app
password: ${DB_PASSWORD}With that configuration and no org.postgresql:postgresql on the runtime classpath, Boot fails earlier than DriverManager with Failed to determine a suitable driver class. Adding the dependency and restarting converts the error into a connection attempt, which is the progress you want. A test that runs on H2 needs the H2 dependency in test scope, plus a test profile that does not reuse the production URL.
5. Drivers in OSGi, jlink and module-path runtimes
java --module-path mods --add-modules java.sql,com.mysql.cj -cp app.jar ProbeA modular runtime needs java.sql and the driver module resolved explicitly; otherwise the service file is present but never read. In OSGi, each bundle needs its own import of java.sql and a fragment or a DataSourceFactory; relying on the automatic module name of a driver JAR is fragile because it changes between releases.
6. Diagnosing without redeploying
System.out.println(System.getProperty("java.class.path"));
System.out.println(Probe.class.getClassLoader());
DriverManager.getDrivers().asIterator().forEachRemaining(d -> System.out.println(d));If the list is empty, the driver is not on the classpath the JVM actually uses. If it contains the driver and the URL still fails, the URL is wrong. Log both once at startup and the next incident takes a minute instead of an afternoon. Checksums of the deployed JARs are worth recording as well; the hash tool produces a SHA-256 for a build artifact that can be compared with CI output.
Common Compilation/Runtime Mistakes & Version Gotchas
Adding Class.forName as the first fix. It only helps when the JAR is present but auto-registration is disabled, which is rare on modern JVMs. Confirm the driver is on the classpath first.
Using provided scope for the driver. The scope means "the container provides it", and quite often nothing does. A shipped application needs runtime.
Keeping the old MySQL driver class name. com.mysql.jdbc.Driver is from Connector/J 5.x. Connector/J 8 and later use com.mysql.cj.jdbc.Driver, and the old name still loads in some versions with a deprecation warning that hides the version mismatch.
Assuming the JVM sees the classpath you exported. CLASSPATH is ignored by java -jar, which uses the JAR manifest. Code that worked under java -cp fails under the launcher script for that reason.
Version notes. Connector/J 9 dropped some legacy behaviours and requires Java 8 or later, with 8.4+ recommended. PostgreSQL JDBC 42.7 changed the default of assumeMinServerVersion and moved to jdbc:postgresql://host:port/db?sslmode=require guidance. Maven's mysql:mysql-connector-java artifact is deprecated in favour of com.mysql:mysql-connector-j, so a copied dependency block may resolve nothing at all.
Reference material: DriverManager and java.sql.Driver.
Official references
primary documentationThe Java documentation that defines the behaviour this guide explains.
Try matching browser tools
All toolsSmall utilities that fit Java work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Java guides
All Java guidesSpring Boot: No qualifying bean of type available
The context could not satisfy a constructor argument. Scan boundaries, missing stereotypes, ambiguous candidates and test slices are the usual reasons.
Method Scope in Java: How Local Variables Work
Understand how variables behave inside Java methods: local variable boundaries, block scope, parameter scope, shadowing, and lifetime implications.
Java: HikariPool connection is not available, request timed out
The HikariCP pool ran out of connections for the whole connectionTimeout. Read the counters, find leaks or slow queries, then size the pool.
Java: DateTimeParseException: Text could not be parsed
The formatter pattern and the input disagree. Check the index in the message, the locale, and whether the text needs a ZonedDateTime instead.
More in Java
All Java guidesThe guides filed next to this one in Java, in library order.