解决错误在Eclipse中的Java SQL Server 2008 R2中的连接(solve er

2019-09-22 04:59发布

我试图SQL Server 2008 R2中使用微软的JDBC驱动程序sqljdbc_4.0 Eclipse IDE中的我的Java应用程序连接,我瞪大眼睛几个时间与Java和SQL Server 2008之间的JDBC连接,我已经尝试了一些,但同样得到错误信息,所以,最后我决定在这里提出的问题与我是什么变得比,我能知道错了我在做什么错误讯息?

我跟着一个链接 ! 链接与SQL Server和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

Answer 1:

您正在使用JDBC驱动程序是依赖于本地SQL Server驱动程序,需要一个路径添加到它的依赖DLL上(sqljdbc_auth.dll)在Java库路径。

要添加到您的Eclipse项目的设置(假设你已经安装了SQL Server驱动程序),这样做:

右键单击该项目在项目资源管理器- >属性- > Java构建路径- >选择sqljdbc4.jar ,所以它扩展- >选择本机库的位置- >编辑- >输入<location of SQL server driver on your machine>/sqljdbc_2.0/enu/auth/x64 - >确定。

结果应该是这样的:



文章来源: solve error in connection between sql server 2008 r2 with java in eclipse