Menu

I can not use jtds on Android 4.0

Ivan Liang
2013-06-04
2013-06-04
  • Ivan Liang

    Ivan Liang - 2013-06-04

    I tried to use jtds on Android 4.0 by following code:

    public class TestThread extends Thread {
    @Override
    public void run() {
    ...
    Connection connection = null;
    String connectionString = "jdbc:jtds:sqlserver://mydatabase.net:1433/database; ssl=required";
    try
    {
    Class.forName("net.sourceforge.jtds.jdbc.Driver");
    connection = DriverManager.getConnection(connectionString , "account", "pwd");
    ...

    and got following error log:

    06-04 09:58:06.683: I/System.out(1648): waiting for debugger to settle...
    06-04 09:58:06.893: I/System.out(1648): debugger has settled (1491)
    06-04 09:58:07.148: E/(1648): file /data/data/com.nvidia.NvCPLSvc/files/driverlist.txt: not found!
    06-04 09:58:07.148: I/(1648): Attempting to load EGL implementation /system/lib//egl/libEGL_tegra_impl
    06-04 09:58:07.153: I/(1648): Loaded EGL implementation /system/lib//egl/libEGL_tegra_impl
    06-04 09:58:07.178: I/(1648): Loading GLESv2 implementation /system/lib//egl/libGLESv2_tegra_impl
    06-04 09:58:09.193: W/AzureTest(1648): Thread start
    06-04 09:58:09.868: W/dalvikvm(1648): VFY: unable to resolve static method 3407: Lcom/sun/net/ssl/SSLContext;.getInstance (Ljava/lang/String;)Lcom/sun/net/ssl/SSLContext;
    06-04 09:58:09.873: W/dalvikvm(1648): Link of class 'Lnet/sourceforge/jtds/ssl/SocketFactoriesSUN$1;' failed
    06-04 09:58:09.873: E/dalvikvm(1648): Could not find class 'net.sourceforge.jtds.ssl.SocketFactoriesSUN$1', referenced from method net.sourceforge.jtds.ssl.SocketFactoriesSUN$TdsTlsSocketFactory.trustManagers
    06-04 09:58:09.873: W/dalvikvm(1648): VFY: unable to resolve new-instance 743 (Lnet/sourceforge/jtds/ssl/SocketFactoriesSUN$1;) in Lnet/sourceforge/jtds/ssl/SocketFactoriesSUN$TdsTlsSocketFactory;
    06-04 09:58:09.878: W/dalvikvm(1648): Link of class 'Lnet/sourceforge/jtds/ssl/SocketFactoriesSUN$1;' failed
    06-04 09:58:15.323: W/dalvikvm(1648): threadid=11: thread exiting with uncaught exception (group=0x41d8c2d0)
    06-04 09:58:15.328: E/AndroidRuntime(1648): FATAL EXCEPTION: Thread-2348
    06-04 09:58:15.328: E/AndroidRuntime(1648): java.lang.NoClassDefFoundError: com.sun.net.ssl.SSLContext
    06-04 09:58:15.328: E/AndroidRuntime(1648): at net.sourceforge.jtds.ssl.SocketFactoriesSUN$TdsTlsSocketFactory.factory(SocketFactoriesSUN.java:174)
    06-04 09:58:15.328: E/AndroidRuntime(1648): at net.sourceforge.jtds.ssl.SocketFactoriesSUN$TdsTlsSocketFactory.getFactory(SocketFactoriesSUN.java:157)
    06-04 09:58:15.328: E/AndroidRuntime(1648): at net.sourceforge.jtds.ssl.SocketFactoriesSUN$TdsTlsSocketFactory.createSocket(SocketFactoriesSUN.java:86)
    06-04 09:58:15.328: E/AndroidRuntime(1648): at net.sourceforge.jtds.jdbc.SharedSocket.enableEncryption(SharedSocket.java:332)
    06-04 09:58:15.328: E/AndroidRuntime(1648): at net.sourceforge.jtds.jdbc.TdsCore.negotiateSSL(TdsCore.java:554)
    06-04 09:58:15.328: E/AndroidRuntime(1648): at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:350)
    06-04 09:58:15.328: E/AndroidRuntime(1648): at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:188)
    06-04 09:58:15.328: E/AndroidRuntime(1648): at java.sql.DriverManager.getConnection(DriverManager.java:175)
    06-04 09:58:15.328: E/AndroidRuntime(1648): at java.sql.DriverManager.getConnection(DriverManager.java:209)
    06-04 09:58:15.328: E/AndroidRuntime(1648): at com.benecheck.azuretest.TestThread.run(TestThread.java:40)

    How do i solve this problem? Thanks!

    Ivan Liang

     
    • John Craig

      John Craig - 2013-06-04

      The critical issue in the exception trace is this:
      java.lang.NoClassDefFoundError: com.sun.net.ssl.SSLContext
      You'll need to include Oracle/Sun's jsse.jar file in your classpath. Presumably you are not using an Oracle/Sun JVM on your Android setup, but you should be able to copy this JAR file from an install of the Oracle/Sun JVM on a PC.

      You should be able to verify that other aspects of your setup on Android are working correctly by setting ssl=false (assuming your target server will accept a non-SSL connection)--this change should by-pass the need for the com.sun.net.ssl.SSLContext class (for testing purposes).

      I hope that helps! Best of luck with this.

       

      Last edit: John Craig 2013-06-04

Log in to post a comment.