1

I am currently working on an Android app and I am attempting to retrieve information from a MySQL database. I am trying to use JDBC as instructed by my professors, but I keep running into problems.

I have installed the MySQL Connector/ODBC 5.3, set a CLASSPATH environment variable for the driver I am attempting to use, which is "mysql-connector-java-5.1.38-bin.jar", and I attempted to import that JAR into my project.

I have attempted to import the JAR in two ways, which are the following:

File > New Module > Import .JAR/.AAR Package > import the mysql connector JAR Then I proceeded to go to File > Project Structure > app > Dependencies > add module dependency

The other way I have attempted to do this was by adding the JAR into the "libs" folder of my project and follow the Project structure path to add a dependency from file.

I am running the latest version of Android Studio 2.0

The build completes successfully when following either of the importing steps however when doing so I get the following error when attempting to run the app:

    Execution failed for task ':app:transformClassesWithInstantRunForDebug'.
    > JSR/RET are not supported with computeFrames option

The only solution I found relevant to this was going to Android Studio Settings and turning the Instant Run option off.

After doing so I received the following error instead:

    Execution failed for task ':app:transformClassesWithDexForDebug'.
    > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException:  java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_77\bin\java.exe'' finished with non-zero exit value 1

The following is my build.gradle(Module:app):

  apply plugin: 'com.android.application'

  android {
compileSdkVersion 23
buildToolsVersion '23.0.3'

defaultConfig {
    applicationId "com.example.JohnDoe.myapp"  //This is not actually the name or the name of the app on there but I changed this for privacy.
    minSdkVersion 14
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled true

}

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

dexOptions {
    incremental true
    javaMaxHeapSize "2048M"
    jumboMode = true
}
  }

  dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.2.1'
compile 'com.squareup.retrofit2:retrofit:2.0.0'
compile 'com.squareup.retrofit2:converter-gson:2.0.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
compile 'com.android.support:multidex:1.0.1'
compile project(':mysql-connector-java-5.1.38-bin')
  }

The following is a link to the whole gradle console output after turning "Instant Run" off: pastebin.com/5kj6Cgeb

Please advise me where to go from here to get the JDBC driver working so I can finish this project. Thank you for your time.

UPDATE 1: Apparently the latest JDBC driver is not fully compatible with Android and causes issues. I installed and imported the previous version (5.0.8) and so far the app at least runs. Will be attempting to implement the driver now and actually develop with it, at which time I will post another update on the outcome.

PCVan
  • 13
  • 1
  • 5

1 Answers1

1

You should not use JDBC in Android Apps as it is targetted to high bandwith, reliable connections to a database server, something you will not achieve on a mobile device. Try to wrap your database in a REST web service instead.

I've read several times that people struggled with using JDBC in Android, it's just not built for beeing used in the Android ecosystem. Not every library is fully compatible with Android, your gradle output suggests that the "dexer" could not convert the jar file to a .dex.

Your provided gradle output show the following error:

com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)

See this question for a possible solution. Ensure you are building with the right Java SDK.

Community
  • 1
  • 1
Jonas Köritz
  • 2,606
  • 21
  • 33
  • I understand that, but that's not the point here. The point is this is a school project, and I was instructed by my professors to use JDBC for this specific project. Is there a way to fix this failure to convert? Perhaps an older version of JDBC would work since I have seen many tutorials with working older JDBC for android? – PCVan Apr 20 '16 at 17:52
  • Did your professor provide a working example of JDBC running in Android? – Jonas Köritz Apr 20 '16 at 17:54
  • No, this course if more of a self taught/self learning experience. We were simply told to implement JDBC for this project. I was given an example of the JAVA code, but not an actual working project. – PCVan Apr 20 '16 at 17:55
  • Yes, over 30 times. Perhaps a maven dependency could work? Any idea how I would set that up instead? – PCVan Apr 20 '16 at 17:58
  • I might have found the solution. I edited my answer, please have a look at the provided link. – Jonas Köritz Apr 20 '16 at 18:01
  • Unfortunately I have to go to class right now so I can't try this solution at the moment. I will attempt everything in that link as soon as I am back from class and I will keep you and my post updated with results. Thank you for your help thus far. – PCVan Apr 20 '16 at 18:07
  • Updated my post. Seems like there are compatibility issues. – PCVan Apr 20 '16 at 22:38