在我的程序中使用 JDBC 连接时,出现以下异常。我使用的是jdk1.6.0_25。
异常(exception):
com.microsoft.sqlserver.jdbc.TDSChannel enableSSL WARNING: TDSChannel ( ConnectionID:1 TransactionID:0x0000000000000000) SSL handshake failed: RSA premaster secret error com.microsoft.sqlserver.jdbc.SQLServerException: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: RSA premaster secret error.
at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(Unknown Source)
at com.microsoft.sqlserver.jdbc.TDSChannel.throwSSLConnectionFailed(Unknown Source)
at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithoutFailover(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.exterro.db.Dummy.main(Dummy.java:22)
The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: RSA premaster secret error.
最佳答案
我在使用 java 8、SQL Server 2008、sqlserver 驱动程序 4.2 时遇到了同样的问题
在对使用 java 7 和 sqldriver 的主要/次要异常有其他提示之后
问题似乎是因为(正如有人所说)sql server 数据库所在的网络与我运行代码的网络不同。第一个网络是 172.x.x.x,第二个网络是 15.x.x.x
用 jtds 驱动程序替换 sqlserver 驱动程序非常有效,感谢下面线程中的人们
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/a36ea16c-cc78-4054-bd02-dd637b1e9a81/warning-tdschannel-when-attempting-to-connect?forum=sqldataaccess
关于java - 连接到 SQLServer 时出现 JDBC 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14229209/