尝试在Windows 7上使用jtds 1.3 + jdk1.8(64)时出现以下错误。
Exception in thread "main" java.lang.RuntimeException: Error initializing DESEngine
at net.sourceforge.jtds.util.DESEngine.init(DESEngine.java:76)
at net.sourceforge.jtds.util.DESEngine.<init>(DESEngine.java:51)
at net.sourceforge.jtds.jdbc.NtlmAuth.answerLmChallenge(NtlmAuth.java:52)
at net.sourceforge.jtds.jdbc.TdsCore.sendNtlmChallengeResponse(TdsCore.java:2179)
at net.sourceforge.jtds.jdbc.TdsCore.login(TdsCore.java:613)
at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:369)
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:183)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at test4.Test4.main(Test4.java:15)
Caused by: java.security.NoSuchAlgorithmException: DES SecretKeyFactory not available
at javax.crypto.SecretKeyFactory.<init>(SecretKeyFactory.java:122)
at javax.crypto.SecretKeyFactory.getInstance(SecretKeyFactory.java:160)
at net.sourceforge.jtds.util.DESEngine.init(DESEngine.java:69)
... 9 more
示例代码:
public static void main(String[] args) throws Exception {
String url = "jdbc:jtds:sqlserver://server:1433/db1;domain=dm1";
String user = "user";
String pwd = "password";
Class.forName("net.sourceforge.jtds.jdbc.Driver");
Connection cn = DriverManager.getConnection(url, user, pwd);
System.out.println("connected!");
}
Java版:
C:\Program Files\Java\jdk1.8.0_40\bin>java -version
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
这是我做的测试:
jtds-1.3(1.3.1)
Windows7 + jdk1.7.79 (32) works
Windows7 + jdk1.7.79 (64) works
Windows7 + jdk1.8.40 (32) works
Windows7 + jdk1.8.40 (64) NOT working
RedHat6.6 + jdk1.7.79 (64) works
RedHat6.6 + jdk1.8.40 (64) works
jtds-1.2.8:
works on any combination of system above.
Windows上有关jtds1.3 + java8(64)的任何已知问题?
答案 0 :(得分:6)
如果使用java 8运行,jtds 1.3.1在创建数据库连接时尝试使用SSL有一个已知的错误。这里记录了:http://sourceforge.net/p/jtds/bugs/725/ 虽然它被标记为已修复,但尚未打包新版本的代码。当我们连接jtds驱动程序时,我们使用URL标志ssl = request,这样,如果服务器支持ssl,我们将建立一个ssl连接。当我们使用java 8时,我们遇到了数据库连接故障,这个bug最终成了原因。你可以签出代码,自己构建驱动程序(就像那样丑陋),但由于它已经超过1。5年,并且尚未发布新的版本,这将是最快的可行修复。