Search code examples
javasql-serverjdbcmssql-jdbc

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


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)


Solution

  • 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";