尝试在Java代码中建立SQL Server数据库连接时出错
我对数据库连接和运行查询等方面的编码相当陌生。我已经看过一些教程和例子,我觉得我已经正确地完成了95%,但肯定有一些小东西我遗漏了
我当前正在尝试与SQL Server数据库建立连接,但不断出现异常:
This driver is not configured for integrated authentication.
下面是我的代码的样子:
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());
}
我想我遇到了一个问题,因为我们的数据库使用Windows Auth。以下是我登录Microsoft SQL Server Management Studio时的情况:
我错过了什么
# 1 楼答案
您可以按照MSDN Documentation通过
JDBC
解决Integrated Authentication
的问题当你尝试这个方法时,要记住两件事:
sqljdbc_auth.dll
文件复制到安装了JDBC驱动程序的计算机上Windows系统路径上的目录中李>sqljdbc_auth.dll
文件,即使操作系统是x64版本。如果在x64处理器上运行64位JVM,请使用x64文件夹中的sqljdbc_auth.dll
文件李>希望这能帮助你解决问题