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