Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JDBC SSL重用会话属性MSSQL_Java_Ssl_Session Reuse - Fatal编程技术网

Java JDBC SSL重用会话属性MSSQL

Java JDBC SSL重用会话属性MSSQL,java,ssl,session-reuse,Java,Ssl,Session Reuse,我正在尝试使用SSL将MSSQL服务器与JDBC连接起来,但希望模拟重用会话。我打开了第一个连接并成功地看到了SSL handshae。 在不关闭第一个会话的情况下,我从同一个客户端(IP、端口)打开了一个新的会话,并希望看到重用会话(短握手)。但实际结果是两次握手。我是否需要发送一些URL属性以请求连接到某个会话ID,或者是否有其他方法? 大声喊我的密码。在连接2连接后的调试打印中,我得到: %% No cached client session ***ClientHello,TLSv1.2

我正在尝试使用SSL将MSSQL服务器与JDBC连接起来,但希望模拟重用会话。我打开了第一个连接并成功地看到了SSL handshae。 在不关闭第一个会话的情况下,我从同一个客户端(IP、端口)打开了一个新的会话,并希望看到重用会话(短握手)。但实际结果是两次握手。我是否需要发送一些URL属性以请求连接到某个会话ID,或者是否有其他方法? 大声喊我的密码。在连接2连接后的调试打印中,我得到:

%% No cached client session
***ClientHello,TLSv1.2 RandomCookie:GMT:1465392528字节={43、89、208、221、13、215、236、167、68、88、125、134、95、233、198、226、193、180、250、181、38、62、144、35、162、215、71、59} 会话ID:{}

意味着我被认可为新客户

Im使用Win7 Java 8、MSSQL server2012

非常感谢

    public void connect() throws SQLException, NoSuchAlgorithmException {

        System.setProperty("java.library.path",System.getProperty("java.library.path")+";C:\\Users\\aviva\\Desktop\\JDBC\\sqljdbc_6.0\\enu\\auth\\x86\\sqljdbc_auth.dll;C:\\Users\\aviva\\Desktop\\JDBC\\sqljdbc_6.0\\enu\\auth\\x64\\sqljdbc_auth.dll");
        String connectionUrl2 = "jdbc:sqlserver://<IP>:<PORT>;databaseName=master;EncryptionMethod=loginSSL";
        try {
            Connection conn1;
            Connection conn2;
            String queryString = "select * from sysobjects where type='u'";

            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            conn1 = DriverManager.getConnection(connectionUrl2, "user", "password");
            System.out.println("con1 is connected...");
            Statement statement1 = conn1.createStatement();
            ResultSet rs1 = statement1.executeQuery(queryString);
            System.out.println("1 results");
            while (rs1.next()) {
                System.out.println(rs1.getString(1));
            }
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            conn2 = DriverManager.getConnection(connectionUrl2, "user", "password");
            System.out.println("con2 is connected...");
            Statement statement2 = conn2.createStatement();
            ResultSet rs2 = statement2.executeQuery(queryString);
            System.out.println("2 results");
            while (rs2.next()) {
                System.out.println(rs2.getString(1));
            }
            conn1.close();
            conn2.close();
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
 }
public void connect()抛出SQLException,NoSuchAlgorithmException{
System.setProperty(“java.library.path”,System.getProperty(“java.library.path”)+“C:\\Users\\aviva\\Desktop\\JDBC\\sqljdbc_6.0\\chs\\auth\\x86\\sqljdbc_auth.dll;C:\\Users\\aviva\\Desktop\\JDBC\\sqljdbc_6.0\\chs\\auth\\x64\\sqljdbc_auth.dll”);
String connectionUrl2=“jdbc:sqlserver://:;databaseName=master;EncryptionMethod=loginSSL”;
试一试{
连接conn1;
连接conn2;
String queryString=“select*from sysobjects,其中type='u'”;
Class.forName(“com.microsoft.sqlserver.jdbc.SQLServerDriver”);
conn1=DriverManager.getConnection(connectionUrl2,“用户”,“密码”);
System.out.println(“con1已连接…”);
语句statement1=conn1.createStatement();
ResultSet rs1=statement1.executeQuery(queryString);
系统输出打印项次(“1个结果”);
while(rs1.next()){
System.out.println(rs1.getString(1));
}
Class.forName(“com.microsoft.sqlserver.jdbc.SQLServerDriver”);
conn2=DriverManager.getConnection(connectionUrl2,“用户”,“密码”);
System.out.println(“con2已连接…”);
语句statement2=conn2.createStatement();
ResultSet rs2=statement2.executeQuery(queryString);
系统输出打印项次(“2个结果”);
while(rs2.next()){
System.out.println(rs2.getString(1));
}
conn1.close();
conn2.close();
}catch(ClassNotFoundException | SQLException e){
e、 printStackTrace();
}
}

不相关,但第一行行不通。1) 您不会将
.dll
添加到库路径,而是添加文件夹。而且不能同时添加32位和64位版本,只需添加适当的版本即可。2) 应该使用
-D
注释行参数设置
java.library.path
,我不相信在内部更改它会起作用。3) 您的代码仍然可以工作,因为DLL仅在
integratedSecurity=true
时才需要,即在不提供用户和密码的情况下。简而言之,删除这一行。另外,自Java6以来,
Class.forName()
就不再需要了。即使你真的使用了它,你也只需要一次。看。首先,只有标题清楚地表明,必须关闭第一个连接,第二个连接才能重用握手。感谢您的评论,这确实是一段肮脏的代码。关于问题本身,在打开另一个连接之前关闭第一个连接也会导致两次握手。建立到数据库的新连接是一个缓慢的操作。TLS握手只是交换的一小部分,所以我不确定你想要实现什么。如果要重用连接,请通过使用连接池重用数据库连接,例如,不要尝试仅重用SSL连接(即使可以,我不确定您是否可以)。不相关,但第一行不起作用。1) 您不会将
.dll
添加到库路径,而是添加文件夹。而且不能同时添加32位和64位版本,只需添加适当的版本即可。2) 应该使用
-D
注释行参数设置
java.library.path
,我不相信在内部更改它会起作用。3) 您的代码仍然可以工作,因为DLL仅在
integratedSecurity=true
时才需要,即在不提供用户和密码的情况下。简而言之,删除这一行。另外,自Java6以来,
Class.forName()
就不再需要了。即使你真的使用了它,你也只需要一次。看。首先,只有标题清楚地表明,必须关闭第一个连接,第二个连接才能重用握手。感谢您的评论,这确实是一段肮脏的代码。关于问题本身,在打开另一个连接之前关闭第一个连接也会导致两次握手。建立到数据库的新连接是一个缓慢的操作。TLS握手只是交换的一小部分,所以我不确定你想要实现什么。如果要重用连接,请通过使用连接池重用数据库连接,例如,不要尝试仅重用SSL连接(即使可以,但我不确定是否可以)。