You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JAR包无法连接SQL Server问题及已验证解决方法

JAR包无法连接SQL Server问题及已验证解决方法

最近碰到个棘手的问题:我写了个带GUI的小工具,点击按钮就能连接本地SQL Server数据库验证连接状态。在NetBeans IDE里运行的时候一切正常,连接毫无障碍,但把项目打包成JAR文件后,程序就没法建立连接了。我已经检查了所有必要的环节——类路径配置没问题,JDBC驱动也放在对应的lib目录里,更奇怪的是连错误提示都没弹出来。

先给大家看看我的测试代码:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    // TODO add your handling code here:
    try {            
        String url = "jdbc:sqlserver://MY_PC\\MYSQLSRV;database=my_database";
        String user="myuser";
        String pass="mypass";
        f = new JFrame();
        
            Connection con = DriverManager.getConnection(url,user,pass);
            if(con != null){
                JOptionPane.showMessageDialog(f, "Connection etablie avec succes");
            }
           
        } catch (SQLException ex) {
            //Logger.getLogger(AuthTest.class.getName()).log(Level.SEVERE, null, ex.getMessage());
            JOptionPane.showMessageDialog(f, "Pas de connection");
        }   
    }   

后来我终于找到了解决方案,而且亲测有效:

我修改了java.security文件中的jdk.tls.disabledAlgorithms配置项,把列表里的TLSv1移除了。

调整完这个配置后,再运行JAR包,数据库连接就正常建立了!

备注:内容来源于stack exchange,提问作者Yacine Limane

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.15 08:53:07