You need to enable JavaScript to run this app. Driver org.h2.Driver不接受jdbcUrl问题及数据库配置修复求助
优惠活动
大模型
产品
解决方案
定价
更多

Driver org.h2.Driver不接受jdbcUrl问题及数据库配置修复求助

解决Driver org.h2.Driver不接受jdbcUrl的配置问题

出现Driver org.h2.Driver claims to not accept jdbcUrl错误,核心原因是数据库配置存在多处错误,同时依赖冲突也加剧了问题,具体修正步骤如下:

1. 修正application.properties中的数据库配置错误

你的配置里有3处关键错误:

  • JDBC URL格式错误:MySQL的URL缺少冒号,正确格式应为jdbc:mysql://而非jdbc:mysql//
  • 驱动类属性名错误:Spring Boot中正确的驱动类配置属性是spring.datasource.driver-class-name,不是spring.datasource.driver-class
  • 驱动类全限定名错误:MySQL Connector/J 8.x(对应Spring Boot 3.x)的驱动类是com.mysql.cj.jdbc.Driver,不是com.cj.jdbc.Driver

修改后的数据库配置段:

#database configuration
spring.datasource.url=jdbc:mysql://localhost:3307/exam?serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=7057@Avi
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

2. 清理不必要的数据库依赖(可选但推荐)

你的pom.xml中同时引入了H2和MySQL驱动,虽然都是runtime scope,但Spring Boot的自动配置可能优先识别H2驱动,导致和MySQL URL不匹配的错误。如果项目不需要H2数据库,建议移除H2依赖:

<!-- 移除该H2依赖 -->
<!--
<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <scope>runtime</scope>
</dependency>
-->

3. 保留正确的JPA配置

你的JPA配置部分无需修改,保持原样即可:

#jpa configuration
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true

完成以上修改后,启动项目即可连接MySQL数据库并自动创建/更新表结构。

内容的提问来源于stack exchange,提问作者avishkar dixit

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 22:52:51