解决eclipse中sql server 2008 r2与java之间的连接错误 [英] solve error in connection between sql server 2008 r2 with java in eclipse
问题描述
我正在尝试在eclipse IDE中使用Microsoft JDBC sqljdbc_4.0驱动程序将SQL Server 2008 r2与我的Java应用程序连接,我用java和sql server 2008之间的JDBC连接进行了几次浏览,但我尝试了一些但又遇到相同错误的问题消息,所以最后决定将问题与错误消息一起放在这里,然后得到什么呢?我可以知道自己在做什么错了?
I am trying to connect SQL server 2008 r2 with my java application using microsoft JDBC sqljdbc_4.0 driver in eclipse IDE, I goggled several time with JDBC connection between java and sql server 2008 and I have tried some of but getting same error message, So lastly am decided to put the question here with error message what am getting than, i can get know what wrong am doing?
我关注了链接!链接以实现与SQL Server和Java的连接.
I followed a link! link for connectivity with SQL Server and Java.
我的Java程序:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Connect
{
public static void main(String[] args) throws Exception
{
String userName = "Abhishek";
String password = "abhishek-nayak";
String url = "jdbc:sqlserver://Abhishek-VAIO\\MSSQLSERVER;databaseName=master;integratedSecurity=true";
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection(url,userName,password);
System.out.println("Connected");
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
我的错误消息是:
Sep 06, 2012 9:09:55 PM com.microsoft.sqlserver.jdbc.AuthenticationJNI <clinit>
WARNING: Failed to load the sqljdbc_auth.dll cause : no sqljdbc_auth in java.library.path
com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated authentication. ClientConnectionId:5cb4d70b-f644-4670-b7bc-a2312b8547b4
at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1667)
at com.microsoft.sqlserver.jdbc.AuthenticationJNI.<init>(AuthenticationJNI.java:60)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:2229)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:2220)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1326)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.abhishek.Connect.main(Connect.java:17)
Caused by: java.lang.UnsatisfiedLinkError: no sqljdbc_auth in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at com.microsoft.sqlserver.jdbc.AuthenticationJNI.<clinit>(AuthenticationJNI.java:35)
... 12 more
推荐答案
您正在使用依赖于本机SQL Server驱动程序的JDBC驱动程序,并且需要向其依赖的DLL添加路径(sqljdbc_auth.dll)到您在Java中的库路径.
You're using a JDBC driver that is dependent on a native SQL Server driver and need to add a path to the DLL it's dependent on (sqljdbc_auth.dll) to your library path in java.
要将其添加到Eclipse项目的设置中(假设您已经安装了SQL Server驱动程序),请执行以下操作:
To add this to settings of your Eclipse project (assuming you already have a SQL Server driver installed) do:
右键单击项目浏览器中的项目->属性-> Java Build Path->选择sqljdbc4.jar
,然后将其展开->选择本机库位置->编辑...->输入<location of SQL server driver on your machine>/sqljdbc_2.0/enu/auth/x64
->确定.
right click the project in Project Explorer -> Properties -> Java Build Path -> select sqljdbc4.jar
, so it expands -> select Native library location -> Edit... -> enter <location of SQL server driver on your machine>/sqljdbc_2.0/enu/auth/x64
-> OK.
结果应如下所示:
这篇关于解决eclipse中sql server 2008 r2与java之间的连接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!