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
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.
– Wagner Soares
Unfortunately it is not the same Case, I tested this solution but it did not work ... thanks so Cara!
– Rafael Andrade
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
– Gabriel Rodrigues
I’ll try to study the code here and I’ll get back to you! Thanks
– Rafael Andrade