I am using MySQL as a database hosted on an Amazon server (AWS).
I am using the AsyncTask class to perform the search in the bank, but when I run on the mobile phone it enters the Exceptions, it seems to cut the connection to the bank.
Maybe the ResultSet is conflicting, because I use the same code to insert values into the bank with executeUpdate and it inserts certinhoooo
public class Tela_Login extends AppCompatActivity {
ConnectionClass connectionClass;
EditText editUsuario, editSenha;
Button btLogin;
TextView textCadastro;
ProgressBar pbbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tela__login);
ConnectionClass connectionClass;
editUsuario = (EditText) findViewById(R.id.editUsuario);
editSenha = (EditText) findViewById(R.id.editSenha);
textCadastro = (TextView) findViewById(R.id.textCadastro);
btLogin = (Button) findViewById(R.id.btLogin);
pbbar = (ProgressBar) findViewById(R.id.pbbar);
pbbar.setVisibility(View.GONE);
btLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
realizarLogin realizarLogin = new realizarLogin();
btLogin.setClickable(false);
realizarLogin.execute("");
}
});
}
public class realizarLogin extends AsyncTask<String,String,String>{
String z = "";
Boolean isSuccess = false;
String usuario = editUsuario.getText().toString();
String senha = editSenha.getText().toString();
@Override
protected void onPreExecute() {
pbbar.setVisibility(View.VISIBLE);
}
@Override
protected void onPostExecute(String r) {
pbbar.setVisibility(View.GONE);
Toast.makeText(Tela_Login.this, r, Toast.LENGTH_SHORT).show();
if (isSuccess) {
Toast.makeText(Tela_Login.this, r, Toast.LENGTH_SHORT).show();
}
}
@Override
protected String doInBackground(String... params) {
if (usuario.trim().equals("") || senha.trim().equals(""))
z = "Por favor os valores!";
else {
try {
Connection con = connectionClass.CONN();
if (con == null) {
z = "Erro ao conectar no banco de dados";
} else {
String query = "select * from Salao where email='" +usuario+"' and senha='" +senha+"'";
Statement stmt = con.createStatement();
ResultSet rs;
rs = stmt.executeQuery(query);
if (rs.next()) {
z = "VOCE CONSEGUIU";
isSuccess = true;
} else {
z = "Invalid Credentials";
isSuccess = false;
}
}
} catch (Exception ex) {
isSuccess = false;
z = "Exceptions";
}
}
btLogin.setClickable(true);
return z;
}
}