Error Mysql and android connection

Asked

Viewed 209 times

1

I’m developing an app that needs to have an external connection and I’m having a running problem, how could I fix this?

Follows the code:

import java.sql.DriverManager;
import java.sql.SQLException;
import com.mysql.jdbc.Driver;
import com.mysql.jdbc.Connection;

    public class conectar {
        Connection conn = null;
        public Connection getConexato() throws ClassNotFoundException, SQLException{
            Class.forName("com.mysql.jdbc.Driver");
            conn = (Connection) DriverManager.getConnection("jdbc:mysql://192.168.1.34:3306/localhost","root","");
            return conn;
        }
    }

import android.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.mysql.jdbc.Driver;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;


public class MainActivity extends AppCompatActivity {
    private Connection conn = null;
    private Statement st;
    private ResultSet rs;
    private String sql;

    @Override

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        conectar Conectar = new conectar();
        try {
            conn = Conectar.getConexato();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            AlertDialog.Builder msg = new AlertDialog.Builder(MainActivity.this);
            msg.setTitle("Conctar!");
            msg.setMessage("Erro! " + e);
            msg.setNeutralButton("OK", null);
            msg.show();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            AlertDialog.Builder msg = new AlertDialog.Builder(MainActivity.this);
            msg.setTitle("Conctar!");
            msg.setMessage("Erro! " + e);
            msg.setNeutralButton("OK", null);
            msg.show();
        }
        Button bt = (Button) findViewById(R.id.btntest);
        bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder msg = new AlertDialog.Builder(MainActivity.this);
                msg.setTitle("Conctar!");
                msg.setMessage("Conectado!");
                msg.setNeutralButton("OK", null);
                msg.show();
                try {
                    conn.close();
                    msg.setTitle("Conctar!");
                    msg.setMessage("Desconectado!");
                    msg.setNeutralButton("OK", null);
                    msg.show();
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        });
    }
}

Logcat:

Error:PARSE ERROR:
Error:unsupported class file version 52.0
Error:...while parsing com/mysql/jdbc/JDBC42CallableStatement.class
Error:1 error; aborting
:app:transformClassesWithDexForDebug FAILED
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.

com.android.build.api.transform.TransformException: java.lang.RuntimeException: 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_101 bin java.exe'' finished with non-zero Exit value 1

  • 1

    In a quick search I found this link http://stackoverflow.com/questions/37902840/got-unsupported-class-file-version-52-0-after-including-a-module-to-a-project see if it is the same case yours.

  • Unfortunately it is not the same Case, I tested this solution but it did not work ... thanks so Cara!

  • I have a link in the project on github maybe I can help, the connection is working properly, ignore the gambiarras kkk https://github.com/luizfps/GLCMonitor

  • I’ll try to study the code here and I’ll get back to you! Thanks

1 answer

0

The error happens because you have not specified the compatibility options in the module itself. It usually happens if your project is with JDK 7, but is installed and using JDK 8, then all modules that will be used in a project have to be compatible with the JDK 7. Otherwise, there will be an error because JDK 7 cannot parse class files that were compiled by JDK 8 and have version 52.

Check:

apply plugin: 'java'

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')

    sourceCompatibility = 1.7
    targetCompatibility = 1.7
}

Details

  • I checked and I REALLY DIDN’T, BUT the time I put and synced hum Gradle, and This Error Happened Here: Error:The 'java' plugin has been Applied, but it is not compatible with the Android plugins.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.