I. HELP: Access Remote MySQL Server Using Connector/J
Posted by: Arthur Chan
Date: May 12, 2016 06:05PM


I have been trying to access from Android Studio 1.5.1 a remote MySQL server version 5.5.45-cll-lve, 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:

Then, I sync-ed the gradle with the project, I figured the dependencies in build.gradle will pull it into the project:
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:
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 {

  protected void onCreate(Bundle savedInstanceState) {
  Connection conn = null;
  Statement stmt = null;
  ResultSet rs = null;
  String TAG = "DEBUG:";

  try {
  } catch (ClassNotFoundException ex) {
  Log.d(TAG, "Cannot find MySQL JDBC Driver!");
  Log.d(TAG, "MySQL JDBC Driver registered\n");

But when I try to run the app, it threw these errors almost immediately:
Error: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)

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 a lost over this, can anyone help with this?

SOrry, I can't seem to post .jpg

Options: ReplyQuote

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.