zoukankan      html  css  js  c++  java
  • 关于Java访问SQL server的错误:The server selected protocol version TLS10 is not accepted by client preferences [TLS12]及安全套接字层(SSL)加密与 SQL Server 建立安全连接

    此笔记记载了本人在使用centos7.6环境下使用java连接sqlserver2008时The server selected protocol version TLS10 is not accepted by client preferences [TLS12]安全套接字层(SSL)加密与 SQL Server 建立安全连接的症状、排查及解决方案。

    环境

    系统:centos7.6

    JDK:openjdk 1.8

    连接库:com.microsoft.sqlserver,mssql-jdbc,6.1.0.jre8

    数据库:SQL server 2008

    症状

    在执行到如下代码时会遇到The server selected protocol version TLS10 is not accepted by client preferences [TLS12]安全套接字层(SSL)加密与 SQL Server 建立安全连接的错误提示。

    public WhiteListResult JudgmentQingJia(String number) throws SQLException {
            DriverManager.registerDriver(new SQLServerDriver());
            Connection connection = null;
            Statement stmt = null;
            try {
                Class.forName(DRIVER);
                connection = DriverManager.getConnection(URL + DATABASE_NAME, USER_NAME, PASSWORD);
                stmt =
                        connection.createStatement(
                                ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
                stmt.setQueryTimeout(1);
                ResultSet resultSet =
                        stmt.executeQuery(
                                String.format(
                                        "SELECT  * FROM user",
                                        number));
    
                boolean find = resultSet.first();
    
                resultSet.close();
    
                return new WhiteListResult(true, "success", find);
            } catch (ClassNotFoundException e) {
                System.out.println(e);
                return new WhiteListResult(true, "驱动问题", false);
            } catch (SQLException e) {
                System.out.println(e);
                return new WhiteListResult(true, e.getMessage(), false);
            } finally {
                if (stmt != null && !stmt.isClosed()) {
                    stmt.close();
                    stmt = null;
                }
    
                if (connection != null && !connection.isClosed()) {
                    connection.close();
                    connection = null;
                }
            }
        }
    

    解决方案

    造成此问题的主要原因是由于算法的配置问题导致。解决方案是修改算法的配置即可。

    # 进入jdk配置目录
    cd /usr/lib/jvm/jre/lib/security
    
    # 编辑配置文件
    nano java.security
    
    # 找到并修改如下参数
    jdk.tls.disabledAlgorithms=SSLv3, RC4, DES, MD5withRSA, DH keySize < 1024, 
        EC keySize < 224, 3DES_EDE_CBC
    
    # 保存并重新启动项目即可
    

    本文来自博客园,作者:一块白板,转载请注明原文链接:https://www.cnblogs.com/ykbb/p/14975938.html

  • 相关阅读:
    python 判断矩阵中每行非零个数的方法
    用Python 绘制分布(折线)图
    统计numpy数组中每个值出现的个数
    pandas 获取不符合条件的dataframe
    Python 中如何判断 list 中是否包含某个元素
    docker与Spring boot的集成:docker-maven-plugin使用
    处理kdevtmpfsi挖矿病毒
    使用docker-maven-plugin推送镜像到远程docker服务器
    docker 开启2375端口,提供外部访问docker
    Spring Boot 配置优先级顺序
  • 原文地址:https://www.cnblogs.com/ykbb/p/14975938.html
Copyright © 2011-2022 走看看