java连接mysql执行ddl,Spring Boot错误org.hibernate.exception.GenericJDBCException:无法打开JDBC连接以执行DDL...

Run the Jar package the spring boot application with data spring jpa and the mysql connector have different results in the Windows 10 environment and the linuxmint environment.

If this application runs on linuxmint it works perfectly, but if it starts in Windows 10 an error like this occurs:

ERROR org.springframework.beans.factory.BeanCreationException:

Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]:

Invocation of init method failed; nested exception is javax.persistence.PersistenceException:

[PersistenceUnit: default] Unable to build Hibernate SessionFactory;

nested exception is org.hibernate.exception.GenericJDBCException:

Unable to open JDBC Connection for DDL execution

this is pom.xml dependencies

org.springframework.boot

spring-boot-starter

org.springframework.boot

spring-boot-starter-logging

org.springframework.boot

spring-boot-starter-test

test

org.springframework.boot

spring-boot-starter-security

org.springframework.boot

spring-boot-starter-data-jpa

mysql

mysql-connector-java

org.controlsfx

controlsfx

8.40.10

de.jensd

fontawesomefx

8.9

org.hibernate

hibernate-jpamodelgen

net.sf.jasperreports

jasperreports

6.2.0

org.apache.poi

poi

3.12

org.jfxtras

jfxtras-all

8.0-r5

org.springframework

spring-context-support

org.apache.commons

commons-lang3

org.slf4j

slf4j-api

org.slf4j

slf4j-log4j12

com.google.zxing

core

3.3.3

com.google.zxing

javase

3.3.3

commons-codec

commons-codec

And this application.properties

# datasourcce

spring.datasource.url=jdbc:mysql://localhost/apotekfxboot

spring.datasource.username=root

spring.datasource.password=

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

# hibernate

spring.jpa.hibernate.ddl-auto=update

spring.jpa.generate-ddl=true

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

spring.jpa.show-sql=true

spring.jpa.properties.hibernate.format_sql=true

Note:

Both of these environments use the same mariadb version, which is 10.1.19.

Coding is done in the linuxmint environment

解决方案

Try changing

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

to

spring.datasource.driverClassName=com.mysql.jdbc.Driver

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个异常通常是由于连接数据库失败引起的,可能的原因包括: 1. 数据库连接池已满。如果您使用数据库连接池来管理数据库连接,可能会出现连接池已满的情况,从而导致新的连接请求失败。您可以检查数据库连接池的配置,并将其调整为适当的大小。如果您使用的是 Tomcat 等 Web 容器,还可以检查容器的最大连接数配置。 2. 数据库服务未启动或已停止。如果数据库服务未启动或已停止,您将无法连接到数据库。您可以检查数据库服务是否正在运行,并尝试重新启动服务。 3. 数据库连接字符串错误。如果您的数据库连接字符串不正确,您将无法连接到数据库。您可以检查连接字符串的格式和参数是否正确。 4. 数据库授权问题。如果您没有正确的权限来连接到数据库,您将无法连接到数据库。您可以检查数据库的授权设置,并确保您具有正确的权限。 5. 数据库驱动程序缺失或不兼容。如果您的数据库驱动程序缺失或不兼容,您将无法连接到数据库。您可以检查数据库驱动程序的版本和兼容性,并确保您使用的驱动程序与您的数据库和应用程序兼容。 6. 数据库连接超时。如果您的数据库连接超时,您将无法连接到数据库。您可以检查数据库连接超时设置,并将其调整为适当的值。 以上是一些可能导致 `CannotCreateTransactionException` 异常的原因。您可以根据具体情况进行相应的排查和解决。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值