Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CheckLogin extends AsyncTask<String,String,String>
- {
- String z = "";
- Boolean isSuccess = false;
- @Override
- protected void onPreExecute()
- {
- // progressBar.setVisibility(View.VISIBLE);
- }
- @Override
- protected void onPostExecute(String r)
- {
- // progressBar.setVisibility(View.GONE);
- Toast.makeText(LoginActivity.this, r, Toast.LENGTH_SHORT).show();
- if(isSuccess)
- {
- Toast.makeText(LoginActivity.this , "Login Successfull" , Toast.LENGTH_LONG).show();
- //finish();
- }
- }
- @Override
- protected String doInBackground(String... params)
- {
- java.sql.Connection con;
- String usernam = params[0];
- String passwordd = params[1];
- if(usernam.trim().equals("")|| passwordd.trim().equals(""))
- z = "Please enter Username and Password";
- else
- {
- try
- {
- con = connectionclass();
- if (con == null)
- {
- z = "Check Your Internet Access!";
- }
- else
- {
- // Change below query according to your own database.
- String query = "select * from owner where mail = '" + usernam.toString() + "' and password = '"+ passwordd.toString() +"' ";
- Statement stmt = con.createStatement();
- ResultSet rs = stmt.executeQuery(query);
- if(rs.next())
- {
- z = "Login successful";
- isSuccess=true;
- con.close();
- }
- else
- {
- z = "Invalid Credentials!";
- isSuccess = false;
- }
- }
- }
- catch (Exception ex)
- {
- isSuccess = false;
- z = ex.getMessage();
- }
- }
- return z;
- }
- }
- @SuppressLint("NewApi")
- public java.sql.Connection connectionclass()
- {
- StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
- StrictMode.setThreadPolicy(policy);
- java.sql.Connection connection = null;
- String ConnectionURL = null;
- try
- {
- Class.forName("com.mysql.jdbc.Driver");
- connection = DriverManager.getConnection(url, un, pas);
- }
- catch (SQLException se)
- {
- Log.e("error here 1 : ", se.getMessage());
- }
- catch (ClassNotFoundException e)
- {
- Log.e("error here 2 : ", e.getMessage());
- }
- catch (Exception e)
- {
- Log.e("error here 3 : ", e.getMessage());
- }
- return connection;
- }
- jdbc:mysql://185.176.43.41:3306/DB_name
Add Comment
Please, Sign In to add comment