Guest User

Untitled

a guest
Mar 22nd, 2018
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. package com.example.a036mca16.login;
  2.  
  3. import android.content.Context;
  4. import android.database.Cursor;
  5. import android.database.sqlite.SQLiteDatabase;
  6. import android.support.v7.app.AlertDialog;
  7. import android.support.v7.app.AppCompatActivity;
  8. import android.os.Bundle;
  9. import android.view.View;
  10. import android.widget.Button;
  11. import android.widget.EditText;
  12. import android.widget.TextView;
  13.  
  14. public class MainActivity extends AppCompatActivity implements View.OnClickListener {
  15. EditText username;
  16. EditText password;
  17. TextView attempts;
  18. Button lbtn;
  19. // int count = 5;
  20. SQLiteDatabase db;
  21. @Override
  22. protected void onCreate(Bundle savedInstanceState) {
  23. super.onCreate(savedInstanceState);
  24. setContentView(R.layout.activity_main);
  25. username = (EditText)findViewById(R.id.edtuname);
  26. password = (EditText)findViewById(R.id.edtpsw);
  27. attempts = (TextView)findViewById(R.id.txtcount);
  28. lbtn = (Button)findViewById(R.id.lbtn);
  29.  
  30. db=openOrCreateDatabase("StudentDB", Context.MODE_PRIVATE, null);
  31. db.execSQL("CREATE TABLE IF NOT EXISTS student(rollno VARCHAR,name VARCHAR,marks VARCHAR);");
  32. db.execSQL("INSERT INTO student VALUES('121','sujith','68');");
  33. lbtn=(Button)findViewById(R.id.lbtn);
  34. lbtn.setOnClickListener(this);
  35. }
  36. @Override
  37. public void onClick(View v)
  38. {
  39. if(username.getText().toString().trim().length()==0||
  40. password.getText().toString().trim().length()==0)
  41. {
  42. showMessage("Error", "Please enter all values");
  43. return;
  44. }
  45. else
  46. {
  47. Cursor c=db.rawQuery("SELECT name FROM student WHERE rollno='"+password.getText()+"'", null);
  48. if(c.moveToFirst())
  49. {
  50. if(username.getText().toString().equals(c.getString(0)))
  51. attempts.setText(c.getString(0)+" Login Successful" );
  52. else
  53. attempts.setText(c.getString(0)+" Login Failed" );
  54. }
  55.  
  56. }
  57.  
  58. }
  59. public void showMessage(String title,String message)
  60. {
  61. AlertDialog.Builder builder=new AlertDialog.Builder(this);
  62. builder.setCancelable(true);
  63. builder.setTitle(title);
  64. builder.setMessage(message);
  65. builder.show();
  66. }
  67. }
Add Comment
Please, Sign In to add comment