连接到MS SQL Server数据库时出错

时间:2017-10-29 22:17:06

标签: java android sql-server database-connection jtds

我正在尝试连接到Android中的MS SQL Server,我在Logcat上遇到以下错误:

Process: za.co.plus94.rate, PID: 22863
java.lang.RuntimeException: An error occurred while executing doInBackground()
 at android.os.AsyncTask$3.done(AsyncTask.java:309)
 at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
 at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
 at java.util.concurrent.FutureTask.run(FutureTask.java:242)
 at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
 at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/ietf/jgss/GSSManager;
 at net.sourceforge.jtds.jdbc.TdsCore.createGssToken(TdsCore.java:4400)
 at net.sourceforge.jtds.jdbc.TdsCore.sendMSLoginPkt(TdsCore.java:1971)
 at net.sourceforge.jtds.jdbc.TdsCore.login(TdsCore.java:617)
 at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:371)
 at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
 at java.sql.DriverManager.getConnection(DriverManager.java:179)
 at java.sql.DriverManager.getConnection(DriverManager.java:144)
 at za.co.plus94.rate.Helpers.ConnectionClass.connClass(ConnectionClass.java:28)
 at za.co.plus94.rate.RateKeywordActivity$SendSuggestion.doInBackground(RateKeywordActivity.java:108)
 at za.co.plus94.rate.RateKeywordActivity$SendSuggestion.doInBackground(RateKeywordActivity.java:95)
 at android.os.AsyncTask$2.call(AsyncTask.java:295)
 at java.util.concurrent.FutureTask.run(FutureTask.java:237)
 at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) 
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
 at java.lang.Thread.run(Thread.java:818) 
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.ietf.jgss.GSSManager" on path: DexPathList[[zip file "/data/app/za.co.plus94.rate-2/base.apk", zip file "/data/app/za.co.plus94.rate-2/split_lib_dependencies_apk.apk", zip file "/data/app/za.co.plus94.rate-2/split_lib_slice_0_apk.apk", zip file "/data/app/za.co.plus94.rate-2/split_lib_slice_1_apk.apk", zip file "/data/app/za.co.plus94.rate-2/split_lib_slice_2_apk.apk", zip file "/data/app/za.co.plus94.rate-2/split_lib_slice_3_apk.apk", zip file "/data/app/za.co.plus94.rate-2/split_lib_slice_4_apk.apk", zip file "/data/app/za.co.plus94.rate-2/split_lib_slice_5_apk.apk", zip file "/data/app/za.co.plus94.rate-2/split_lib_slice_6_apk.apk", zip file "/data/app/za.co.plus94.rate-2/split_lib_slice_7_apk.apk", zip file "/data/app/za.co.plus94.rate-2/split_lib_slice_8_apk.apk", zip file "/data/app/za.co.plus94.rate-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/za.co.plus94.rate-2/lib/arm64, /vendor/lib64, /system/lib64]]
 at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
 at net.sourceforge.jtds.jdbc.TdsCore.createGssToken(TdsCore.java:4400) 
 at net.sourceforge.jtds.jdbc.TdsCore.sendMSLoginPkt(TdsCore.java:1971) 
 at net.sourceforge.jtds.jdbc.TdsCore.login(TdsCore.java:617) 
 at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:371) 
 at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184) 
 at java.sql.DriverManager.getConnection(DriverManager.java:179) 
 at java.sql.DriverManager.getConnection(DriverManager.java:144) 
 at za.co.plus94.rate.Helpers.ConnectionClass.connClass(ConnectionClass.java:28) 
 at za.co.plus94.rate.RateKeywordActivity$SendSuggestion.doInBackground(RateKeywordActivity.java:108) 
 at za.co.plus94.rate.RateKeywordActivity$SendSuggestion.doInBackground(RateKeywordActivity.java:95) 
 at android.os.AsyncTask$2.call(AsyncTask.java:295) 
 at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
 at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) 
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
 at java.lang.Thread.run(Thread.java:818) 
Suppressed: java.lang.ClassNotFoundException: org.ietf.jgss.GSSManager
 at java.lang.Class.classForName(Native Method)
 at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
 at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
        ... 17 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

我认为问题来自:java.lang.NoClassDefFoundError:解析失败:Lorg / ietf / jgss / GSSManager;而且我不知道如何解决它。

这是我的DB Connection方法类:

public Connection connClass(String username, String password, String database, String server){
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    Connection connection = null;

    String ConnectionURL = null;

    try{
        Class.forName("net.sourceforge.jtds.jdbc.Driver");
        ConnectionURL = "jdbc:jtds:sqlserver://" + server + ";databaseName=" + database + ";user" + username + ";password" + password + ";";
        connection = DriverManager.getConnection(ConnectionURL);
    }catch (SQLException ex){
        Log.e("CONNECTION", ex.getMessage());
    }catch(ClassNotFoundException ex){
        Log.e("CONNECTION", ex.getMessage());
    }catch (Exception ex){
        Log.e("CONNECTION", ex.getMessage());
    }

    return connection;

}
}

我也启用了MultiDex。

2 个答案:

答案 0 :(得分:0)

尝试使用以前版本的jtds,ver。 1.2.7确切地说。尝试使用那个适合我的那个

答案 1 :(得分:0)

进行此更改

Class.forName("net.sourceforge.jtds.jdbc.Driver");
ConnectionURL = "jdbc:jtds:sqlserver://" + server + "/" + database;
connection = DriverManager.getConnection(ConnectionURL, username, password);