在我的Android项目中,我使用 jtds.jdbc 连接到SQL Server数据库。在尝试连接时,我写了错误的连接字符串,该错误提示:“Network error IOException: Connection timed out
”。
Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
Connection DbConn = DriverManager.getConnection(192.168.xx.xx:1085/SomeDatabase;integratedSecurity=true;user=xxx;password=xxx;instanceName=SomeInstance);
Statement stmt = DbConn.createStatement();
ResultSet reset = stmt.executeQuery(" select * from SomeTable");
Log.i("RESULTS", reset.getString(1));
DbConn.close();
这证明了JTDS已包含在我的项目中并正在工作。但是当我写出正确的连接字符串时,我收到了以下错误:
11-28 08:09:31.929: I/dalvikvm(13041): Could not find method org.ietf.jgss.GSSManager.getInstance, referenced from method net.sourceforge.jtds.jdbc.TdsCore.createGssToken
11-28 08:09:31.929: W/dalvikvm(13041): VFY: unable to resolve static method 7980: Lorg/ietf/jgss/GSSManager;.getInstance ()Lorg/ietf/jgss/GSSManager;
11-28 08:09:31.929: D/dalvikvm(13041): VFY: replacing opcode 0x71 at 0x0001
11-28 08:09:31.929: D/dalvikvm(13041): VFY: dead code 0x0004-0090 in Lnet/sourceforge/jtds/jdbc/TdsCore;.createGssToken ()[B
11-28 08:09:31.949: I/dalvikvm(13041): Could not find method org.ietf.jgss.GSSContext.initSecContext, referenced from method net.sourceforge.jtds.jdbc.TdsCore.sendGssToken
11-28 08:09:31.949: W/dalvikvm(13041): VFY: unable to resolve interface method 7974: Lorg/ietf/jgss/GSSContext;.initSecContext ([BII)[B
11-28 08:09:31.949: D/dalvikvm(13041): VFY: replacing opcode 0x72 at 0x0008
11-28 08:09:31.949: W/dalvikvm(13041): VFY: unable to resolve exception class 1082 (Lorg/ietf/jgss/GSSException;)
11-28 08:09:31.949: W/dalvikvm(13041): VFY: unable to find exception handler at addr 0x4c
11-28 08:09:31.949: W/dalvikvm(13041): VFY: rejected Lnet/sourceforge/jtds/jdbc/TdsCore;.sendGssToken ()V
11-28 08:09:31.949: W/dalvikvm(13041): VFY: rejecting opcode 0x0d at 0x004c
11-28 08:09:31.949: W/dalvikvm(13041): VFY: rejected Lnet/sourceforge/jtds/jdbc/TdsCore;.sendGssToken ()V
11-28 08:09:31.949: W/dalvikvm(13041): Verifier rejected class Lnet/sourceforge/jtds/jdbc/TdsCore;
11-28 08:09:31.949: D/AndroidRuntime(13041): Shutting down VM
11-28 08:09:31.949: W/dalvikvm(13041): threadid=1: thread exiting with uncaught exception (group=0x40018560)
11-28 08:09:32.189: E/AndroidRuntime(13041): FATAL EXCEPTION: main
11-28 08:09:32.189: E/AndroidRuntime(13041): java.lang.VerifyError: net.sourceforge.jtds.jdbc.TdsCore
11-28 08:09:32.189: E/AndroidRuntime(13041): at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:359)
11-28 08:09:32.189: E/AndroidRuntime(13041): at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
11-28 08:09:32.189: E/AndroidRuntime(13041): at java.sql.DriverManager.getConnection(DriverManager.java:180)
11-28 08:09:32.189: E/AndroidRuntime(13041): at java.sql.DriverManager.getConnection(DriverManager.java:145)
11-28 08:09:32.189: E/AndroidRuntime(13041): at fip.cis.k.PostavkeActivity$1.onClick(PostavkeActivity.java:50)
11-28 08:09:32.189: E/AndroidRuntime(13041): at android.view.View.performClick(View.java:2501)
11-28 08:09:32.189: E/AndroidRuntime(13041): at android.view.View$PerformClick.run(View.java:9107)
11-28 08:09:32.189: E/AndroidRuntime(13041): at android.os.Handler.handleCallback(Handler.java:587)
11-28 08:09:32.189: E/AndroidRuntime(13041): at android.os.Handler.dispatchMessage(Handler.java:92)
11-28 08:09:32.189: E/AndroidRuntime(13041): at android.os.Looper.loop(Looper.java:130)
11-28 08:09:32.189: E/AndroidRuntime(13041): at android.app.ActivityThread.main(ActivityThread.java:3835)
11-28 08:09:32.189: E/AndroidRuntime(13041): at java.lang.reflect.Method.invokeNative(Native Method)
11-28 08:09:32.189: E/AndroidRuntime(13041): at java.lang.reflect.Method.invoke(Method.java:507)
11-28 08:09:32.189: E/AndroidRuntime(13041): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
11-28 08:09:32.189: E/AndroidRuntime(13041): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
11-28 08:09:32.189: E/AndroidRuntime(13041): at dalvik.system.NativeStart.main(Native Method)
我的 jtds-1.3.1.jar 位于libs文件夹和Android私有库中,并在订单和导出中进行检查。
GSSManager 是Java的一个类。但我确实在构建中包含了jre7。
我确实尝试过:
有什么建议吗?
编辑:在org.ietf.jgss.GSSManager和net.sourceforge.jrds.jdbc.TdsCore类中找到了sendGssToken()方法
答案 0 :(得分:13)
我刚刚使用了一个早期的jar,它起作用了。