关于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

保存并重新启动项目即可

Original: https://www.cnblogs.com/ykbb/p/14975938.html
Author: 一块白板
Title: 关于Java访问SQL server的错误:The server selected protocol version TLS10 is not accepted by client preferences [TLS12]及安全套接字层(SSL)加密与 SQL Server 建立安全连接

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/610426/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • python 内置模块

    #!/usr/bin/env python -*- coding:utf-8 -*- import time #时间模块 print(time.time())#当前时间戳 #本地时…

    Linux 2023年6月13日
    0110
  • 异步、邮件、定时任务

    异步、邮件、定时任务 14.1 异步任务 编写一个业务测试类 文件路径:com–dzj–service–AsynService.java @Se…

    Linux 2023年6月14日
    0125
  • 搭建部署Docker

    Docker安装准备: 首先看下服务器是否有旧版本,如果有需要卸载并且安装依赖 然后下载docker仓库repo源: 安装完成后查看docker仓库版本信息: yum安装docke…

    Linux 2023年6月8日
    0139
  • Redis相关监控命令

    1、查询Redis并发量,连续统计模式redis-cli –stat 2、redis最大连接数config get maxclients 3、redis当前连接数、阻塞…

    Linux 2023年5月28日
    0109
  • 更快的排序——归并排序!基于分而治之的对数复杂度的排序Merge Sort

    Merge Sort Algorithm The merge sort algorithm is defined recursively: If the list is of si…

    Linux 2023年6月13日
    0116
  • html2canvas生成并下载图片

    html <div id="downChart"> div> jq new html2canvas(document.getElementBy…

    Linux 2023年6月7日
    0114
  • Dockerfile 构建镜像

    从 Dockerfile 构建镜像涉及三个步骤 创建工作目录 编写 Dockerfile 规格 使用 docker build 命令构建镜像 1. 创建工作目录 这个根据应用实际情…

    Linux 2023年6月6日
    0134
  • Redis info参数总结(转)

    可以看到,info的输出结果是分几块的,有Servers、Clients、Memory等等,通过info后面接这些参数,可以指定输出某一块数据。 我刚开始在Gentoo上装的默认版…

    Linux 2023年5月28日
    0146
  • WPF 界面打不开提示 System.ArithmeticException Overflow or underflow in the arithmetic operation 异常

    本文告诉大家如何解决界面打不开,抛出 System.ArithmeticException: Overflow or underflow in the arithmetic ope…

    Linux 2023年6月6日
    0106
  • Vector底层实现

    vector的三个私有成员 :_start 记录初始位置, _finish 记录有效字符, _endofstoage 记录容量大小 vector会存储的类型不同,所以要用模版来定类…

    Linux 2023年6月13日
    0125
  • CH343芯片应用—硬件设计

    CH343属于沁恒第三代USB转串口芯片系列的单串口型号,基于经典版CH340芯片完成技术革新,实现USB转高速异步串口,支持最高6Mbps串口波特率。 电源设计 CH343芯片有…

    Linux 2023年6月7日
    0192
  • alloc_pages的实现浅析

    alloc_pages的使用 struct page *alloc_pages(gft_t gfp, unsigned int order) alloc_pages定义于 inux…

    Linux 2023年6月7日
    0134
  • 到底能不能用 join

    互联网上一直流传着各大公司的 MySQL 军规,其中关于 join 的描述,有些公司不推荐使用 join,而有些公司则规定有条件的使用 join, 它们都是教条式的规定,也没有详细…

    Linux 2023年6月13日
    0104
  • [数据库]ACID、CAP、BASE特性

    SQL与noSQL 对比项 关系型SQL 非关系型SQL 关系表 数据集(键值/JSON文档/哈希表/其它) 结构化、提前定义表结构 动态调整模式,非结构化 纵向扩展,提高处理能力…

    Linux 2023年6月13日
    0115
  • 秒搞VirtualBox 、CentOS 的安装过程

    镜像下载、域名解析、时间同步请点击阿里云开源镜像站 一、介绍背景: VirtualBox : 由德国 InnoTek 软件公司出品 Open Source Software, OS…

    Linux 2023年5月27日
    0111
  • python写一个双色球彩票计算器

    首先声明,赌博一定不是什么好事,也完全没有意义,不要指望用彩票发财。之所以写这个,其实是用来练手的,可以参考这个来预测一些其他的东西,意在抛砖引玉。 啰嗦完了,马上开始,先上伪代码…

    Linux 2023年6月6日
    0122
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球