SQLServer与32位和64位环境中的Windows身份验证连接

时间:2015-11-10 21:52:27

标签: java sql-server jdbc

我有一个Java应用程序,它分发给少数用户。应用程序使用Windows身份验证连接到SQLServer数据库。 从几个SO-Posts(SO6938717SO17277001)我了解到,通常的做法是在VM参数中设置所需库的路径。

java -Djava.library.path = / path / to / my / dll -jar / my / classpath / goes / here MainClass

我的应用程序在32位和64位环境中运行,但是对于每个环境,都有一个具有相同名称的特定库:sqljdbc_auth.dll。

我可以设置两个路径作为VM参数: java -Djava.library.path = / auth / x86; / auth / x64 -jar / my / classpath / goes / here MainClass

但这不起作用。我怎样才能确保Windows身份验证在32位和64位环境中工作?

1 个答案:

答案 0 :(得分:1)

看看这里:

possible-values-of-processor-architecture

考虑到这一点,您可以通过以下方式分发您的应用:

/libs/yourjarfiles.jar
/AMD64/sqljdbc_auth.dll (the 64bit version)
/x86/sqljdbc_auth.dll (the 32 bit version)

并使用

调用它
java -Djava.library.path=.\%PROCESSOR_ARCHITECTURE%\ -jar /my/classpath/goes/here MainClass

安装的绝对路径在库路径设置中可能是一个好主意。

编辑:解决64位主机上32位Java的上述问题

Helper-Class:Architecture.java

public class Architecture {    
    public static void main(String[] args) {
        System.out.print(System.getProperty("os.arch"));
    }   
}

CMD启动您的计划

@ECHO OFF
for /f %%i in ('java -classpath /my/classpath/goes/here/ Architecture') do set JAVA_ARCH=%%i
java -Djava.library.path=path/to/dlls/%JAVA_ARCH%/ -cp /my/classpath/goes/here MainClass

您必须像这样命名您的目录以匹配可能的os.arch值:

/x86  - 32 bit DLL goes here
/amd64  - 64 bit DLL goes here

我想如果您知道库的路径,您甚至可以在os.arch的运行时基于MainClass系统属性附加该路径。

相关问题