1

I using google GCM github example

I want add a sql connection in this example

so I write this try in eclipse , this is successed

    String driver = "com.mysql.jdbc.Driver"; 
    String url = "jdbc:mysql://ip:port/"; 
    String user = "root"; 
    String password = "123456"; 
    try { 
        sql setting ...
        }
    } 
    catch(ClassNotFoundException e) { 
        System.out.println("No"); 
        e.printStackTrace(); 
    } 
    catch(SQLException e) { 
        e.printStackTrace(); 
    } 

but when I created a *.java in GCM example and copy to *.java

and add this code to bulid.gradle(Module.app)

it's failed

sourceCompatibility = 1.7
targetCompatibility = 1.7

this is error message

Error:Gradle: Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add 
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.

how to fix it?

BTW commend cmd java -version

java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
名宏 鄭
  • 115
  • 1
  • 5
  • 12

3 Answers3

1

I found that the best way to connect android to MySQL is to use an xamp server (you can download by googling xamp) then you wanna use php scripts to connect to android, the php will also get and add or delete data and link to your java code. You don't need the driver and you could do it in eclipse but android studio is easier, Good tutorial https://youtube.com/watch?v=HK515-8-Q_w

Steve
  • 43
  • 8
0

You must have a web service used for data transferring bettween two platform your android application and your database you can use PHP NodeJS JEE .NET Golang ..... it impossible to connect directly we use JSON or XML for communication.

https://www.tutorialspoint.com/android/android_php_mysql.htm