Spring boot RuntimeException java.lang.RuntimeException: Driver claims to not accept jdbcUrl happens when an inappropriate data source url is configured to connect to a database. The database driver can accept the jdbc url in a particular format. If the jdbc url format is different from expected one, RuntimeException Driver claims to not accept jdbcUrl will be thrown in the spring boot application.
The url format of the data source is different for each database. .Databases such as MySql, Oracle, SQL Server, Postgress, H2, Derby, HSQL, MongoDB use different formats when using the respective database drivers in the spring boot application
The exception java.lang.RuntimeException: Driver claims to not accept jdbcUrl will be thrown from the database driver. The exception will show the driver class name and the invalid datasource url. The database driver could not understand the format of the datasource url configured in the spring boot application.properties.
Exception
The spring boot exception will show the error message as like below for the databases. The database servers such as oracle, mysql, SQL Server, Postgres, MongoDB will throw error messages with the respective database driver class name.
java.lang.RuntimeException: Driver com.mysql.cj.jdbc.Driver claims to not accept jdbcUrl, jdbc:mysql://localhost:3306/test
java.lang.RuntimeException: Driver oracle.jdbc.driver.OracleDriver claims to not accept jdbcUrl,
java.lang.RuntimeException: Driver com.microsoft.sqlserver.jdbc.SQLServerDriver claims to not accept jdbcUrl,
java.lang.RuntimeException: Driver org.postgresql.Driver claims to not accept jdbcUrl,
java.lang.RuntimeException: Driver org.h2.Driver claims to not accept jdbcUrl,
java.lang.RuntimeException: Driver org.apache.derby.jdbc.EmbeddedDriver claims to not accept jdbcUrl,
2020-12-02 07:34:43.759 INFO 88099 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-12-02 07:34:43.774 ERROR 88099 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactory' threw exception; nested exception is java.lang.RuntimeException: Driver com.mysql.cj.jdbc.Driver claims to not accept jdbcUrl, jdbc:mysql:driver://localhost:3306/test
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:655) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactory' threw exception; nested exception is java.lang.RuntimeException: Driver com.mysql.cj.jdbc.Driver claims to not accept jdbcUrl, jdbc:mysql:driver://localhost:3306/test
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
... 20 common frames omitted
Caused by: java.lang.RuntimeException: Driver com.mysql.cj.jdbc.Driver claims to not accept jdbcUrl, jdbc:mysql:driver://localhost:3306/test
at com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:110) ~[HikariCP-3.4.5.jar:na]
at com.zaxxer.hikari.pool.PoolBase.initializeDataSource(PoolBase.java:325) ~[HikariCP-3.4.5.jar:na]
at com.zaxxer.hikari.pool.PoolBase.<init>(PoolBase.java:114) ~[HikariCP-3.4.5.jar:na]
How to reproduce this exception
If the datasource url contains an unacceptable format in the application.properties file, the database driver may attempt to connect the database using the datasource url. Since the data source url format could not be interpreted by the database driver, the exception would be thrown by the database driver. The configuration of the file application.properties below will replicate this exception.
application.properties
spring.datasource.url=jdbc:mysql:driver://localhost:3306/test
Output
Caused by: java.lang.RuntimeException: Driver com.mysql.cj.jdbc.Driver claims to not accept jdbcUrl, jdbc:mysql:driver://localhost:3306/test
at com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:110) ~[HikariCP-3.4.5.jar:na]
at com.zaxxer.hikari.pool.PoolBase.initializeDataSource(PoolBase.java:325) ~[HikariCP-3.4.5.jar:na]
at com.zaxxer.hikari.pool.PoolBase.<init>(PoolBase.java:114) ~[HikariCP-3.4.5.jar:na]
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:108) ~[HikariCP-3.4.5.jar:na]
Root Cause
The database driver uses the data source url to connect to the database. If the data source url should have a particular format for processing and establishing a database connection. If the data source url is in a different format, the format cannot be interpreted by the database driver. As a consequence, the database driver will throw this Runtime Exception java.lang.RuntimeException: Driver claims to not accept jdbcUrl at the start of the spring boot application.
Solution 1
The datasource url should be in the recommended format for the respective database drivers. If the datasource url format should be as shown below for the respective databases.
Mysql
spring.datasource.url=jdbc:mysql://localhost:3306/testdb
Oracle
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:xe
SQL Server
spring.datasource.url=jdbc:sqlserver://localhost:1433;databaseName=testdb
Postgres
spring.datasource.url=jdbc:postgresql://localhost:5432/testdb
MongoDB
spring.data.mongodb.uri=mongodb://root:rootpassword@localhost:27017/testdb
H2
jdbc:h2:~/testdb
Derby
jdbc:derby:testdb
Solution 2
The exception would be caused by the mismatch of the database driver and the data source url. For instance, the Oracle database driver is configured in the pom.xml file. The data source url can be configured to the MySql database. Check the url of the data source and the database driver.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>