SQL Server: connect to database using NTLM authentication using Java 8

喜你入骨 提交于 2020-04-18 05:41:54

问题


I am trying to connect to SQL Server using my credentials.

The data I am provided is to connect is the following:

  • Server: Ccddb294\oss_prod
  • Database: OSS_DW

Code:

public static void main(String arg[]) throws ClassNotFoundException, SQLException {
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

        String dbURL = "jdbc:sqlserver://ccddb294.corp.corpcom.com:1433;databaseName=OSS_DW;integratedSecurity=true";

        Connection conn = DriverManager.getConnection(dbURL,"corp\\e21290","Anjali@1234");
        if (conn != null) {
            System.out.println("Connected");
        }
    }

I am not sure where to give oss_prod in server name. When I try to connect, I get this error:

Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: Integrated authentication failed. ClientConnectionId:26ddec01-2e7e-46c3-8165-4f3646da5e7c

Can someone validate if the dbURL which I created is correct as per specification or do I need to add odd_prod - but if so, where? (Note: The dll file is correctly placed in bin and i am able to connect to server at least but not able to authenticate only)


回答1:


After lots of hit and trials.

Following is correct db URL:

"jdbc:sqlserver://ccddb294.corp.corpcom.com:1433;
instanceName=oss_prod;
databaseName=OSS_DW;
integratedSecurity=true;
domain=corp;
authenticationscheme=NTLM;
user=e21290;
password=Anjali@1234";


来源:https://stackoverflow.com/questions/60831323/sql-server-connect-to-database-using-ntlm-authentication-using-java-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!