无法将Spring Boot应用程序与SQL SERVER数据库连接。

huangapple go评论68阅读模式
英文:

Not able to connect spring boot application with SQL SERVER Database

问题

我正在尝试将我的Spring Boot应用程序与SQL Server数据库连接,但它抛出一个异常并显示:

2020年8月18日16:58:11.580 错误 14800 --- [主] com.zaxxer.hikari.pool.HikariPool:HikariPool-1 - 池初始化期间出现异常。

com.microsoft.sqlserver.jdbc.SQLServerException:驱动程序无法使用安全套接字层(SSL)加密建立与SQL Server的安全连接。错误:“SQL Server没有返回响应。连接已关闭。”


*然而,我可以连接到Oracle数据库,但当我尝试连接到SQL Server时出现问题*。

**这是application.properties文件**

spring.datasource.url=jdbc:sqlserver://192.168.*.*\\DB2008;databaseName=mydbname
spring.datasource.username=myuser
spring.datasource.password=mypassword
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect

以下是详细错误信息:

2020年8月18日16:58:11.580 错误 14800 --- [主] com.zaxxer.hikari.pool.HikariPool:HikariPool-1 - 池初始化期间出现异常。

com.microsoft.sqlserver.jdbc.SQLServerException:驱动程序无法使用安全套接字层(SSL)加密建立与SQL Server的安全连接。错误:“SQL Server没有返回响应。连接已关闭。ClientConnectionId:37aa16bd-92f0-4af0-a090-06f2349cb51a”。。
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:2924) ~[mssql-jdbc-7.4.0.jre8.jar:na]
    at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1881) ~[mssql-jdbc-7.4.0.jre8.jar:na]
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2484) ~[mssql-jdbc-7.4.0.jre8.jar:na]
英文:

I am trying to connect my spring boot application with sql server database but it throwing an Exception and saying :

020-08-18 16:58:11.580 ERROR 14800 --- [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Exception during pool initialization.

    com.microsoft.sqlserver.jdbc.SQLServerException: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "SQL Server did not return a response. The connection has been closed. .

However I am able to connect with oracle database the issue arises when I try to connect with sql server.

here is the application.properties file

spring.datasource.url=jdbc:sqlserver://192.168.*.*\\DB2008;databaseName=mydbname
spring.datasource.username=myuser
spring.datasource.password=mypassword
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect

here is the detailed error:

2020-08-18 16:58:11.580 ERROR 14800 --- [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Exception during pool initialization.

com.microsoft.sqlserver.jdbc.SQLServerException: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "SQL Server did not return a response. The connection has been closed. ClientConnectionId:37aa16bd-92f0-4af0-a090-06f2349cb51a".
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:2924) ~[mssql-jdbc-7.4.0.jre8.jar:na]
	at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1881) ~[mssql-jdbc-7.4.0.jre8.jar:na]
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2484) ~[mssql-jdbc-7.4.0.jre8.jar:na]

答案1

得分: 0

我已通过以下步骤解决了这个问题:

编辑 C:\Program Files\Java\jdk1.8.0_251\jre\lib\security\java.security

找到下面的变量,它将有多个逗号分隔的值,移除我下面提到的一个值:

查找:jdk.tls.disabledAlgorithms=

移除:3DES_EDE_CBC

这应该会解决这个问题!

英文:

I have resolved this issue by following the below steps:

Edit C:\Program Files\Java\jdk1.8.0_251\jre\lib\security\java.security

find the below variable it will have multiple comma separated values remove one value which I have mentioned below:

Find: jdk.tls.disabledAlgorithms=

Remove: 3DES_EDE_CBC

This should fix it!

答案2

得分: -1

在这种情况下,您可以尝试以下步骤。

  1. 确保您的 SQL 服务器正在本地运行(您是否尝试连接到远程 SQL 服务器?)
  2. 或者,在您的 URL 中,在数据库名称之后使用此语句 jdbc:mysql://IP:3306/someDatabase?autoReconnect=true&useSSL=false
英文:

In this case can you can try the following steps.

  1. Make sure that your SQL server is running locally(Are you trying to connect to a remove SQL server?)
  2. Alternatively, In your URL after your Data base name use this statement jdbc:mysql://IP:3306/someDatabase?autoReconnect=true&useSSL=false

huangapple
  • 本文由 发表于 2020年8月18日 20:21:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/63468491.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定