• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps HELP: Access Remote MySQL Server Using JDBC !

ac4android

Well-Known Member
Hi.

I have been trying to access a remote MySQL server using MySQL Connector/J mysql-connector-java-5.1.38-bin.jar, but first, I'll have to make sure the app can even find the driver!

I downloaded the .jar from MySQL and dropped it into app/libs, relying on the app/src/build.gradle to implement it, like this:
applibsgradle.JPG
Then, I sync-ed the gradle with the project, I figured the dependencies in build.gradle will pull it into the project:
Code:
dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  testCompile 'junit:junit:4.12'
  compile 'com.android.support:appcompat-v7:23.2.1'
  compile 'com.android.support:design:23.2.1'
}

This is my minimalist MainActivity.java for testing whether A/S can find the JDBC driver:
Code:
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class MainActivity extends Activity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  Connection conn = null;
  Statement stmt = null;
  ResultSet rs = null;
  String TAG = "DEBUG:";

  try {
  Class.forName("com.mysql.jdbc.Driver");
  } catch (ClassNotFoundException ex) {
  Log.d(TAG, "Cannot find MySQL JDBC Driver!");
  ex.printStackTrace();
  return;
  }
  Log.d(TAG, "MySQL JDBC Driver registered\n");
  }
}

But when I try to run the app, it threw these errors almost immediately:
applibsgradle22.JPG


The error message leads me to believe it might be a version incompatibility here between jdk1.7.0 and the Connector/J.

I am at the moment lost, can anyone help with this?
 
... Gradle Console error message:

UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.RuntimeException: Exception parsing classes
at com.android.dx.command.dexer.Main.processClass(Main.java:752)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:718)
at com.android.dx.command.dexer.Main.access$1200(Main.java:85)
at com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1645)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:672)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:574)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:311)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)
Caused by: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
at com.android.dx.command.dexer.Main.parseClass(Main.java:764)
at com.android.dx.command.dexer.Main.access$1500(Main.java:85)
at com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1684)
at com.android.dx.command.dexer.Main.processClass(Main.java:749)
... 12 more
1 error; aborting


FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_40\bin\java.exe'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED


P.S. I have used Connector/J in Eclipse successfully, logging in and executing SQL, getting resultset back and formatted nicely... Doesn't seem to work for Android ???

Total time: 1 mins 35.182 secs
 
Why do you think that a library designed to work with the Oracle JRE will necessarily work in the Android platform?
 
Why do you think that a library designed to work with the Oracle JRE will necessarily work in the Android platform?

It worked so well in Java SDK 1.7 that I got carried away and tried to do same in Android, which obviously does not work.

OK, back to PHP :)
 
Pity though, would be nice if they released a version for Android.
 
Back
Top Bottom