When the data are correct, the method works, but when I change the password in the database, this method works indefinitely. I would like to if the password or the user is incorrect, the application stopped and show an information notification "or user password is wrong".
To display the information I plan to use AlertDialog and I know how to do it, just I do not know how to connect this with my method myMethod()
Any ideas ?
public void myMethod()
{
Connection conn = null;
Statement stmt = null;
try {
StrictMode.ThreadPolicy ab = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(ab);
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(url2, user2, pass2);
stmt = conn.createStatement();
String sql = "SELECT abc FROM this";
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
Double ba3 = rs.getDouble("abc");
list.add(ba3, rs.getDouble("abc"));
}
} catch (SQLException se)
{
se.printStackTrace();
} catch (Exception e)
{
e.printStackTrace();
} finally {
try {
if (stmt != null)
conn.close();
} catch (SQLException se)
{
}
try {
if (conn != null)
conn.close();
} catch (SQLException se)
{
se.printStackTrace();
}
}
}
edit1:
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
myMethod();
}
});