Error Connection mysql and android

1

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

Follow 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

    
asked by anonymous 27.09.2016 / 20:26

1 answer

0

The error happens because you did not specify the compatibility options in the module itself. Usually happens if your project is JDK 7 , but is installed and using JDK 8 , then all the modules that will be used in a project must be compatible with or JDK 7 . Otherwise, there will be an error because JDK 7 can not 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

27.09.2016 / 21:06