[英]SQLServer connection with windows authentification in 32- and 64-bit environments
I have a Java Application which is distributed to a few users. 我有一个Java应用程序,已分发给一些用户。 The application connets to a SQLServer Database using windows authentification.
该应用程序使用Windows身份验证连接到SQLServer数据库。 From several SO-Posts ( SO6938717 , SO17277001 ) I learned that it is common practice to set a path to the needed library in the VM arguments.
从几篇SO帖子( SO6938717 , SO17277001 )中,我了解到通常的做法是在VM参数中设置所需库的路径。
java -Djava.library.path=/path/to/my/dll -jar /my/classpath/goes/here MainClass java -Djava.library.path = / path / to / my / dll -jar / my / classpath / goes / here MainClass
My Application runs on 32- and 64bit environments, but for every environment there is a specific library with the same name: sqljdbc_auth.dll. 我的应用程序在32位和64位环境上运行,但是对于每个环境,都有一个具有相同名称的特定库:sqljdbc_auth.dll。
I can set two paths as VM arguments: java -Djava.library.path=/auth/x86;/auth/x64 -jar /my/classpath/goes/here MainClass 我可以将两个路径设置为VM参数:java -Djava.library.path = / auth / x86; / auth / x64 -jar / my / classpath / goes / here MainClass
But this doesn't work. 但这是行不通的。 How can I ensure, that windows authentification works in 32- and 64bit environments?
如何确保Windows身份验证在32位和64位环境中工作?
Have a look here: 在这里看看:
possible-values-of-processor-architecture 处理器体系结构的可能值
With this in mind you can distribute your app this way: 考虑到这一点,您可以通过以下方式分发应用程序:
/libs/yourjarfiles.jar
/AMD64/sqljdbc_auth.dll (the 64bit version)
/x86/sqljdbc_auth.dll (the 32 bit version)
And call it using 并使用
java -Djava.library.path=.\%PROCESSOR_ARCHITECTURE%\ -jar /my/classpath/goes/here MainClass
Absolute Path to your install might be a good idea in library-path setting. 在库路径设置中,安装的绝对路径可能是个好主意。
EDIT: Addressing the mentioned concerns for 32bit Java on 64bit host 编辑:解决了在64位主机上对32位Java提到的问题
Helper-Class: Architecture.java 助手类:Architecture.java
public class Architecture {
public static void main(String[] args) {
System.out.print(System.getProperty("os.arch"));
}
}
CMD to start your program 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
You'd have to name your directories like this to match possible os.arch values: 您必须像这样命名目录,以匹配可能的os.arch值:
/x86 - 32 bit DLL goes here
/amd64 - 64 bit DLL goes here
I guess if you'd know the path for the libraries you could even append that path based on os.arch
System property at runtime of MainClass
. 我想,如果你想知道库基础上,你甚至可以追加一条路径的路径
os.arch
在运行时系统属性MainClass
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.