Java Spring Boot JPA 数据库连接问题

问题描述 投票:0回答:1

我正在开发 Java Spring Boot 应用程序,并且在通过 JPA 连接到数据库时遇到问题。 JPA 无法连接到我的数据库。我尝试了很多 url 配置,但连接失败并且出现这样的异常:

java.lang.RuntimeException: Driver com.microsoft.sqlserver.jdbc.SQLServerDriver claims to not accept jdbcUrl

我正在使用 Microsoft SQL Server localdb。这是我的 application.properties 配置

spring.application.name=Two4H
server.port=8080

spring.datasource.url=jdbc:jtds:sqlserver://.\\MSSQLLocalDB\\Two4H;integratedSecurity=true;TrustServerCertificate=true

spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLServerDialect

这是我在 IntelliJ 中的数据库连接,我想将其连接到我的应用程序: Database connection in IntelliJ

java spring spring-boot jpa spring-data-jpa
1个回答
0
投票

对于 SQL Server URL 和驱动程序类应该是

spring.datasource.url=jdbc:sqlserver://MSSQLLocalDB:1433;database=Two4H;integratedSecurity=true;TrustServerCertificate=true
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
© www.soinside.com 2019 - 2024. All rights reserved.