Microsoft JDBC驱动程序在Java代码中有奇怪的行为

问题描述 投票:0回答:1

[我已经尝试过使用Java代码来使用Microsoft JDBC驱动程序来在启用了SSL协议的SQL实例和具有NTLMV2协议的SQL Server上获得连接。

我正在使用Windows身份验证来获取连接,该连接将同时使用SSL和NTLMV2协议。

但是奇怪的是,我们能够建立连接java JDBC客户端,而无需同时为NTLMV2和SSL设置java属性。

有人可以帮助我解释为什么使用Microsoft JDBC驱动程序会发生这种奇怪的情况。

请找到我的Java代码段,该代码段正在使用连接URL来获取与通过SSL和NTLMV2协议启用的SQL实例的连接。

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;


public class SqlJdbcConnection 
{
    String dbDriver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
    String connectionUrl = "";

    private void connect()
    {
        Connection conn=null;
        Statement stmt=null;
        ResultSet rset=null;
        try 
        {
            Class.forName(dbDriver);
        } 
        catch (ClassNotFoundException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return;
        }  
        try
        {           
            connectionUrl = "jdbc:sqlserver://192.168.11.215:1433;databaseName=master;integratedSecurity=true";         
            Properties infoProperties=new Properties();
            infoProperties.put("UserName","administrator");
            infoProperties.put("Password","abc098ABC");
            infoProperties.put("domain","mas");
            infoProperties.put("authenticationScheme","NTLM");
            conn = DriverManager.getConnection(connectionUrl, infoProperties);
            if(conn==null)
            {
                System.out.println("Connection is null");
                return;
            }
            stmt=conn.createStatement();
            rset = stmt.executeQuery("select @@version");
            while(rset.next())
            {
                System.out.println(rset.getString(1));
            }

        }
        catch (Exception e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }  
        finally
        {
            if(rset!=null)
            {
                try 
                {
                    rset.close();
                } catch (Exception e2) {
                    // TODO: handle exception
                }
            }
            if(stmt!=null)
            {
                try 
                {
                    stmt.close();
                } catch (Exception e2) {
                    // TODO: handle exception
                }
            }
            if(conn!=null)
            {
                try 
                {
                    conn.close();
                } catch (Exception e2) {
                    // TODO: handle exception
                }
            }
        }

    }
    public static void main(String[] args)
    {
        // TODO Auto-generated method stub
        SqlJdbcConnection sqljdbc=new SqlJdbcConnection();
        sqljdbc.connect();      }
}

提前感谢

java sql-server jdbc driver
1个回答
0
投票

JDBC规范中未强制要求支持SSL / TLS。那么你无法在每个驱动程序中都期望得到它。

以下属性也用于NTLM V2身份验证:

domain = domainName (optional)
user = userName
password = password
integratedSecurity = true

无意中您已经在使用NTLM v2身份验证

© www.soinside.com 2019 - 2024. All rights reserved.