【问题标题】:Getting the SQL Server Connection Exception获取 SQL Server 连接异常
【发布时间】:2020-11-14 20:40:01
【问题描述】:

我在尝试使用 JDBC 连接到 SQL Server 时遇到连接异常。

有人可以帮忙解决这个问题吗?

我正在使用 sqljdbc4.jar 文件连接到 SQL Server

代码如下

String dbURL = "jdbc:sqlserver://10.156.54.123;encrypt=false;DatabaseName=PRA;sslProtocol=TLSv1;";
 String user = "username";
 String pass = "password";
 conn = DriverManager.getConnection(dbURL, user, pass);

这是个例外。

2020 年 11 月 14 日晚上 8:33:01 com.microsoft.sqlserver.jdbc.TDSChannel enableSSL 信息:java.security 路径:/usr/java/jdk1.8.0_261-amd64/jre/lib/security 安全提供商:[SUN 1.8 版、SunRsaSign 1.8 版、SunEC 1.8 版、SunJSSE 1.8 版、SunJCE 1.8 版、SunJGSS 1.8 版、SunSASL 1.8 版、XMLDSig 1.8 版、SunPCSC 1.8 版] SSLContext 提供者信息:Sun JSSE 提供者(PKCS12、SunX509/PKIX 密钥/信任工厂、SSLv3/TLSv1/TLSv1.1/TLSv1.2/TLSv1.3) SSLContext 提供者服务: [SunJSSE:KeyPairGenerator.RSA -> sun.security.rsa.RSAKeyPairGenerator$Legacy 别名:[1.2.840.113549.1.1,OID.1.2.840.113549.1.1] , SunJSSE: Signature.SHA1withRSA -> sun.security.rsa.RSASignature$SHA1withRSA 别名:[1.2.840.113549.1.1.5, 1.3.14.3.2.29, OID.1.2.840.113549.1.1.5] 属性:{SupportedKeyClasses=java.security.interfaces.RSAPublicKey|java.security.interfaces.RSAPrivateKey} , SunJSSE: SSLContext.TLS -> sun.security.ssl.SSLContextImpl$TLSContext 别名:[SSL] , SunJSSE: SSLContext.TLSv1 -> sun.security.ssl.SSLContextImpl$TLS10Context 别名:[SSLv3] , SunJSSE: Signature.MD2withRSA -> sun.security.rsa.RSASignature$MD2withRSA 别名:[1.2.840.113549.1.1.2,OID.1.2.840.113549.1.1.2] 属性:{SupportedKeyClasses=java.security.interfaces.RSAPublicKey|java.security.interfaces.RSAPrivateKey} , SunJSSE: KeyFactory.RSA -> sun.security.rsa.RSAKeyFactory$Legacy 别名:[1.2.840.113549.1.1,OID.1.2.840.113549.1.1] , SunJSSE: Signature.MD5withRSA -> sun.security.rsa.RSASignature$MD5withRSA 别名:[1.2.840.113549.1.1.4,OID.1.2.840.113549.1.1.4] 属性:{SupportedKeyClasses=java.security.interfaces.RSAPublicKey|java.security.interfaces.RSAPrivateKey} , SunJSSE: KeyStore.PKCS12 -> sun.security.pkcs12.PKCS12KeyStore , SunJSSE: TrustManagerFactory.SunX509 -> sun.security.ssl.TrustManagerFactoryImpl$SimpleFactory , SunJSSE: KeyManagerFactory.SunX509 -> sun.security.ssl.KeyManagerFactoryImpl$SunX509 , SunJSSE: TrustManagerFactory.PKIX -> sun.security.ssl.TrustManagerFactoryImpl$PKIXFactory 别名:[SunPKIX, X509, X.509] , SunJSSE: KeyManagerFactory.NewSunX509 -> sun.security.ssl.KeyManagerFactoryImpl$X509 别名:[PKIX] , SunJSSE: SSLContext.Default -> sun.security.ssl.SSLContextImpl$DefaultSSLContext , SunJSSE: SSLContext.TLSv1.1 -> sun.security.ssl.SSLContextImpl$TLS11Context , SunJSSE: Signature.MD5andSHA1withRSA -> sun.security.ssl.RSASignature , SunJSSE: SSLContext.TLSv1.3 -> sun.security.ssl.SSLContextImpl$TLS13Context , SunJSSE: SSLContext.TLSv1.2 -> sun.security.ssl.SSLContextImpl$TLS12Context ] java.ext.dirs:/usr/java/jdk1.8.0_261-amd64/jre/lib/ext:/usr/java/packages/lib/ext com.microsoft.sqlserver.jdbc.SQLServerException:驱动程序无法使用安全套接字层 (SSL) 加密建立与 SQL Server 的安全连接。错误:“意外重新抛出”。

【问题讨论】:

    标签: java sql-server jdbc


    【解决方案1】:

    您只需按照以下步骤解决您的问题:---

    您只需: 转到java文件夹:---

     1)Find file “java.security” in folder “jre\conf\security”
       
        
    2)`In this java.security file, find “3DES_EDE_CBC” linked to “jdk.tls.disabledAlgorithms”`
        
    3)Remove it!
        
        Sample:
        If file "C:\Users\myUser\AppData\jre\conf\security\java.security"
        
        ORIGINAL:
        
        jdk.tls.disabledAlgorithms=SSLv3, RC4, DES, MD5withRSA, DH keySize < 1024,
        EC keySize < 224, 3DES_EDE_CBC, anon, NULL
        
        NEW (after removing “3DES_EDE_CBC”):
        
        jdk.tls.disabledAlgorithms=SSLv3, RC4, DES, MD5withRSA, DH keySize < 1024,
        EC keySize < 224, anon, NULL
    

    【讨论】:

    • 非常感谢。它工作得很好。我没有更新原始文件,而是将文件作为参数传递 java -Djava.security.properties=
    • 欢迎朋友。是的,你也可以这样做,但要确保“3DES_EDE_CBC”不应该在那里。
    • 您似乎从其他地方复制了此内容。请提供必要的署名和指向该来源的链接。如果这是你自己写的,请编辑它以修复格式(普通文本不属于代码块)。
    • 我是这个平台的新手,不知道如何装饰文字伙伴。别担心,我已经面临这个问题 n 更多 mssql 问题
    • 我还必须从jdk.tls.disabledAlgorithms 中删除TLSv1, TLSv1.1。见stackoverflow.com/a/68149843/606662
    猜你喜欢
    • 2011-07-28
    • 2012-03-06
    • 2012-04-19
    • 1970-01-01
    • 1970-01-01
    • 2011-09-16
    • 1970-01-01
    • 1970-01-01
    • 2014-05-08
    相关资源
    最近更新 更多