0

I had done a lot of searches about how to connect an android app to a firebird DB but still cannot do it.

First of all this is my code to create a connection:

@NonNull
public static void createConnection() throws SQLException {
    if (connection == null || connection.isClosed()) {
        Properties props = new Properties();

        props.setProperty("user", "###");
        props.setProperty("password", "####");
        props.setProperty("encoding", "UTF8");

        try {
            Class.forName("org.firebirdsql.jdbc.FBDriver");
            connection = DriverManager.getConnection("jdbc:firebirdsql://<HOST>:<PORT>/<DATABASE>.fdb", props);
        } catch (SQLException | ClassNotFoundException e) {
            e.printStackTrace();
            Log.e(MY_LOG_TAG, "Falhou ao criar conexão com o Banco! -> " + e.getMessage());
        }
    }
}

Considerations:

  1. As saw on https://stackoverflow.com/a/57036670/4628993, JDBC Jaybird (aka. jaybird-full-4.0.0.java8.jar) does not work on Android:

    java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/resource/Referenceable; at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:454)

So i check the answer's link that pointed me to a Android solution: (https://sourceforge.net/projects/androidjaybird)

  1. Android Jaybird (last update 2017-03-30)

I downloaded the Jaybird_2_2_12.aar and clean my project. Install the *.aar as a new module (new module > aar > Jaybird_2_2_12.aar) and sync with gradle:

FAILURE: Build failed with an exception.
  • What went wrong: Execution failed for task ':app:mergeLibDexDebug'.

    Could not resolve all files for configuration ':app:debugRuntimeClasspath'. Failed to transform artifact 'Jaybird_2_2_12.aar (project :Jaybird_2_2_12)' to match attributes {artifactType=android-dex, dexing-enable-desugaring=true, dexing-is-debuggable=true, dexing-min-sdk=29, org.gradle.usage=java-runtime}. Execution failed for DexingNoClasspathTransform: /home/vapstor/Workana/RoyalFarma/Jaybird_2_2_12/build/.transforms/9b92b1a4ee0f4f8ba116c8e17cff3dd0/jetified-Jaybird_2_2_12-runtime.jar. Error while dexing.

also logs me:

Compatible side by side NDK version was not found. Default is 20.0.5594570.

EDIT:

I forgot to mention that i downloaded an project from here https://www.firebirdsql.org/en/firebird-3-0/#Android too, but it seems that is to install a firebird database on android devices, i need to access it only.

Acauã Pitta
  • 654
  • 1
  • 9
  • 16
  • So install NDK v20. It is still available in the SDK Tools dialog (check "show package details") in Android Studio. Reminder: [JDBC vs Web Service for Android](https://stackoverflow.com/q/15853367/295004) – Morrison Chang Apr 02 '20 at 04:16
  • 2
    It is generally not a good idea to use JDBC drivers from Android. Direct access to a database from an Android device is slow, and relatively insecure. It would be better to create a REST service to mediate between your app and the database. – Mark Rotteveel Apr 02 '20 at 08:29

0 Answers0