1

I'm fairly new to coding for database connections and running queries and all that. I've looked over some tutorials and examples and I feel like I've got 95% of this done correctly but there's gotta be something small I'm missing.

I'm currently trying to make a connection to a SQL Server database and I keep getting the exception:

This driver is not configured for integrated authentication.

Here is what my code looks like:

try {
        String url = "jdbc:sqlserver://serverName;DatabaseName=database;integratedSecurity=true";
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        Connection conn = DriverManager.getConnection(url, "username", "password");
        Statement stmt = conn.createStatement();
        ResultSet rs;

        rs = stmt.executeQuery("select * from database.dbo.table\n" +
                "  where column = 2785 \n" +
                "  AND anotherColumn = 3");
        while ( rs.next() ) {
            String condition = rs.getString("Condition");
            System.out.println(condition);
        }
        conn.close();
    } catch (Exception e) {
        System.err.println("Got an exception! ");
        System.err.println(e.getMessage());
    }

I think I'm running into an issue because our databases use Windows Auth. Here's what that looks like when I log into Microsoft SQL Server Management Studio:

enter image description here

What am I missing here?

jarlh
  • 42,561
  • 8
  • 45
  • 63
user1818298
  • 509
  • 2
  • 8
  • 23
  • Do you have "the sqljdbc_auth.dll file to a directory on the Windows system path on the computer where the JDBC driver is installed" ? https://learn.microsoft.com/en-us/sql/connect/jdbc/building-the-connection-url#Connectingintegrated – Winter Jun 08 '17 at 14:22

1 Answers1

0

You can follow the MSDN Documentation to resolve your problems with Integrated Authentication via JDBC.

Two things to keep in mind when you try this out:

  • To use integrated authentication, copy the sqljdbc_auth.dll file to a directory on the Windows system path on the computer where the JDBC driver is installed.
  • If you are running a 32-bit Java Virtual Machine (JVM), use the sqljdbc_auth.dll file in the x86 folder, even if the operating system is the x64 version. If you are running a 64-bit JVM on a x64 processor, use the sqljdbc_auth.dll file in the x64 folder.

Hope this helps you resolve your issue.

N00b Pr0grammer
  • 4,503
  • 5
  • 32
  • 46