【问题标题】:SQLException - Connection reset errorSQLException - 连接重置错误
【发布时间】:2017-05-19 04:12:49
【问题描述】:

我正在尝试使用 SQLJDBC4 jar 文件和 JDK 1.6 与 SQL Server 2008 R2 建立 jdbc 连接。我正在使用 Netbeans IDE 并添加了 SQLJDBC4 jar 并在服务的“数据库”部分中添加了数据库的路径。代码如下:

package connect2;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Connect2 {


    public static void main(String[] args) throws SQLException {

   Connection conn;
        conn = null;
           System.out.println("Done....");

           try
           {

               Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

               conn = DriverManager.getConnection ("jdbc:sqlserver://172.17.39.13\\CRM:1433;databaseName=crm_xchanging","crm_xchanging","Welcome001");
               System.out.println ("Database connection established");


           }
           catch (ClassNotFoundException e)
           {
               System.out.println (e);
           }
           catch (SQLException ex)
           {
               System.out.println(" error");
           }


          finally
         {
             if (conn != null)
              {

                       try{

               Statement st = conn.createStatement();
                ResultSet res = st.executeQuery("SELECT * FROM  usertable");
                System.out.println("User Name: " );
                        while (res.next()) {
                                String employeeName = res.getString("user_name");
                                System.out.println(employeeName);
                                            }
                    conn.close();
    }
                 catch(SQLException ex){
  System.err.println("SQLException information");

  while(ex!=null) {
  System.err.println ("Error msg: " + ex.getMessage());
  System.err.println ("SQLSTATE: " + ex.getSQLState());
  System.err.println ("Error code: " + ex.getErrorCode());
  ex = ex.getNextException(); 
// For drivers that support chained exceptions
  }}




               }
           }

       }

   }

这是我得到的输出:

run:
Done....
Database connection established
SQLException information
Error msg: Connection reset
SQLSTATE: 08S01
Error code: 0
BUILD SUCCESSFUL (total time: 1 second)

我认为代码或 JDK 没有任何错误。我也尝试设置最大编号。 SQL Server 的活动连接数为 0(无限)。我该如何解决这个问题?

【问题讨论】:

  • 您必须调试并查看 InnerException 才能知道导致错误的原因
  • 您能说得更具体一点吗?如何在 Netbeans 中做到这一点?

标签: sql-server-2008 jdbc


【解决方案1】:

Java 6u29 中引入了一个已知错误,该错误会导致 SSL 失败,特别是 SQL Server 2008 R2。 An Atlassian Fisheye troubleshooting page 表示修复不完整。

Oracle 在 6u30 中提供了修复,但至少有一个受影响的 客户端甚至没有 Java 1.7 工作。

在我的开发团队中,我们发现这个错误也会影响 Java 8。 Fisheye 文章中的一项建议是使用 JVM 标志禁用 CBC 保护,这也适用于带有 SQL Server 2008 R2 连接的 SSL Java 8 SSL。

-Djsse.enableCBCProtection=false

另一个建议是恢复到 Java 1.6.0_24。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-03
    • 2015-01-10
    • 1970-01-01
    • 1970-01-01
    • 2013-03-06
    • 2012-02-19
    • 1970-01-01
    相关资源
    最近更新 更多