Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.musyrif.loginmyguardian;
- import android.os.AsyncTask;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.EditText;
- import android.widget.TextView;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.Statement;
- public class MainActivity extends AppCompatActivity {
- private EditText username, password;
- private TextView text;
- private String ustr, pstr;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- username = (EditText) findViewById(R.id.username);
- password = (EditText) findViewById(R.id.password);
- text = (TextView) findViewById(R.id.textView);
- System.out.println(ustr);
- }
- public void click (View v){
- ustr = username.getText().toString();
- pstr = password.getText().toString();
- new get().execute(ustr, pstr);
- }
- private class get extends AsyncTask<String, Void, Integer>{
- @Override
- protected Integer doInBackground(String... users) {
- String uname= users[0];
- String pw = users[1];
- String result = new String();
- result = "";
- int x=0;
- try{
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection("jdbc:mysql://192.168.43.121:3306/myguardian","mg","mg123");
- Statement stmt = con.createStatement();
- ResultSet rs = stmt.executeQuery("select * from users where username = '"+uname+"' and password = '"+pw+"';");
- while(rs.next()) {
- //result = rs.getString(2)+rs.getString(3);
- x++;
- }
- con.close();
- return x;
- }catch(Exception e) {
- System.out.println(e);
- return x;
- }
- }
- @Override
- protected void onPostExecute(Integer result){
- if (result == 1){
- text.setText("Logged in");
- setContentView(R.layout.loggedin);
- }
- else {
- text.setText("Wrong credentials");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement