Android上的java.lang.NoClassDefFoundError:org.firebirdsql.jdbc.FBDataSource错误

时间:2016-05-28 05:49:45

标签: java android firebird jaybird

与Firebird数据库的连接:

当我尝试将我的Android应用程序连接到Firebird数据库时,我遇到了以下错误。

我的LogCat:

  

致命的例外:主要                                                                                              处理:com.example.hms.firebirdconnection,PID:26717                                                                                               java.lang.NoClassDefFoundError:org.firebirdsql.jdbc.FBDataSource                                                                                                   在   org.firebirdsql.jdbc.AbstractDriver.createDataSource(AbstractDriver.java:138)                                                                                                   在   org.firebirdsql.jdbc.AbstractDriver.connect(AbstractDriver.java:124)                                                                                                   在java.sql.DriverManager.getConnection(DriverManager.java:179)                                                                                                   在java.sql.DriverManager.getConnection(DriverManager.java:213)                                                                                                   在   com.example.hms.firebirdconnection.MainActivity $ 1.onClick(MainActivity.java:42)                                                                                                   在android.view.View.performClick(View.java:4780)                                                                                                   在android.view.View $ PerformClick.run(View.java:19866)                                                                                                   在android.os.Handler.handleCallback(Handler.java:739)                                                                                                   在android.os.Handler.dispatchMessage(Handler.java:95)                                                                                                   在android.os.Looper.loop(Looper.java:135)                                                                                                   在android.app.ActivityThread.main(ActivityThread.java:5254)                                                                                                   at java.lang.reflect.Method.invoke(Native Method)                                                                                                   在java.lang.reflect.Method.invoke(Method.java:372)                                                                                                   在   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:903)                                                                                                   在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

我正在使用jaybird-full-2.2.3并将依赖项添加为模块依赖项。

我的代码是:

    b.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            try {

                Class.forName("org.firebirdsql.jdbc.FBDriver");
            } catch (Exception e) {
                e.printStackTrace();
                System.err.println(e.getMessage());
            }
            try {



                Connection connection DriverManager.getConnection("jdbc:firebirdsql://xxx.xxx.x.x:3050//C:/User/DBNAME", "username", "password");

                String sSql="selecta.TDID,a.DOCTORNAME,a.ROOMNAME,a.TOKEN from TOKEN_DISPLAY a  where a.EMPID=2";
                Statement stmt = connection.createStatement();
                ResultSet rs = stmt.executeQuery(sSql);
                String dr = "";
                if (rs.next()) {
                    dr = rs.getString("DOCTORNAME");
                }
                System.out.println("drrrrrrrrrrr=" + dr);
                );
                rs.close();
            } catch (SQLException e1) {
                e1.printStackTrace();
                return;
            }
            return;
        }


    });

摇篮:

apply plugin:'com.android.application'

android {     compileSdkVersion 23     buildToolsVersion“23.0.3”

defaultConfig {
    applicationId "com.example.hms.firebirdconnection"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}


buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro' 
          }
      }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile files('libs/jaybird-full-2.2.10.jar')
}

3 个答案:

答案 0 :(得分:1)

错误消息显示java.lang.NoClassDefFoundError: org.firebirdsql.jdbc.FBDataSource。您的库中没有此特定类。请从https://github.com/FirebirdSQL/jaybird/releases/download/v2.2.10/Jaybird-2.2.10-JDK_1.8.zip下载驱动程序并查看结果。

答案 1 :(得分:0)

好像你还没有添加jar文件 一旦你添加了模块依赖项,转到项目视图并复制lib文件夹中的jar文件,它将解析方法调用然后

答案 2 :(得分:0)

看起来你正在使用普通的Jaybird(用于Java)。 Jaybird不能在Android上使用,因为它依赖于Android上没有的某些接口和类。

您需要使用"Android Firebird JDBC Driver port",这是专门针对Android的Jaybird端口。不幸的是,自Jaybird 2.2.4以来,该项目的维护者还没有更新它。