今天在處理SQLServer數據庫鏈接時,出現瞭如下問題: (下邊有解決方案)
java
com.microsoft.sqlserver.jdbc.SQLServerException: 驅動程序沒法經過使用安全套接字層(SSL)加密與 SQL Server 創建安全鏈接。錯誤:「RSA premaster secret error」。 ClientConnectionId:d1c3978f-3be0-496f-883d-add6cb86d5c3 at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1745) at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1704) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1401) at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1068) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:904) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:451) at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1014) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at com.yonyou.migrationtool.bs.dao.SQLServerDao.newConnection(Unknown Source) at com.yonyou.migrationtool.bs.dao.BizDaoHandler.invoke(Unknown Source) at com.sun.proxy.$Proxy2.insertDB(Unknown Source) at com.yonyou.migrationtool.bs.service.impl.AccountServiceImpl.saveDB(Unknown Source) at com.yonyou.migrationtool.bs.service.impl.AccountServiceImpl.transfer(Unknown Source) at com.yonyou.migrationtool.vo.TransferTask.start(Unknown Source) at com.yonyou.migrationtool.bs.service.Scheduler$WorkThread.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: javax.net.ssl.SSLKeyException: RSA premaster secret error at sun.security.ssl.RSAClientKeyExchange.<init>(Unknown Source) at sun.security.ssl.ClientHandshaker.serverHelloDone(Unknown Source) at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source) at sun.security.ssl.Handshaker.processLoop(Unknown Source) at sun.security.ssl.Handshaker.process_record(Unknown Source) at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source) at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source) at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source) at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1630) ... 15 more Caused by: java.security.NoSuchAlgorithmException: SunTlsRsaPremasterSecret KeyGenerator not available at javax.crypto.KeyGenerator.<init>(KeyGenerator.java:169) at javax.crypto.KeyGenerator.getInstance(KeyGenerator.java:223) at sun.security.ssl.JsseJce.getKeyGenerator(Unknown Source) ... 25 more
上網找了好多解決方案,不是湊合試的,就是copy別人的.沒有一個像樣的方案.找了好多外文網站,也沒什麼合適的方式.sql
首先說一下我復現問題的方式:
數據庫
1.在eclipse裏運行個人程序鏈接SQLServer數據庫進行操做,沒問題!eclipse用的jdk7-64位.安全
2.打包成jar,用jre來運行的時候,就會拋出上邊的異常.(另外若是你們運行在不一樣環境或者切換不一樣jdk的時候,我以爲均可以歸類爲這種問題)eclipse
從異常中能夠看到:ide
RSA premaster secret error
說明這個是加密異常. 那麼jdk中對應的包就是sunjce_provider.jar,這個包在{JAVA_HOME}\jre\lib\ext下.oop
而在jre中的這個包就會拋出異常.那麼就乾脆用jdk中的這個包替換掉jre中的這個包,問題天然就解決了.sqlserver
個人這個現象可能不能解決全部相似的問題,可是至少能給你們提供一些建議也就好的
網站