Advertisement
Guest User

Untitled

a guest
Aug 26th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. package com.example.dell.foodcourt;
  2.  
  3.  
  4. import android.content.ContentValues;
  5. import android.content.Context;
  6. import android.database.Cursor;
  7. import android.database.SQLException;
  8. import android.database.sqlite.SQLiteDatabase;
  9. import android.database.sqlite.SQLiteOpenHelper;
  10. import android.sax.StartElementListener;
  11. import android.widget.Toast;
  12.  
  13. public class FoodCourt_UserLoginDatabase{
  14. Context context;
  15. FoodCourt_LoginData foodCourt_loginData;
  16. SQLiteDatabase db;
  17.  
  18. public FoodCourt_UserLoginDatabase(Context context){
  19. foodCourt_loginData=new FoodCourt_LoginData(context);
  20. }
  21.  
  22. SQLiteDatabase db = foodCourt_loginData.getWritableDatabase();
  23. ContentValues contentValues = new ContentValues();
  24. contentValues.put(FoodCourt_LoginData.USERNAME, username);
  25. contentValues.put(FoodCourt_LoginData.USERPWD, userpwd);
  26. contentValues.put(FoodCourt_LoginData.USERMOBILE, usermble);
  27. db.insertWithOnConflict(FoodCourt_LoginData.TABLENAME, null, contentValues, SQLiteDatabase.CONFLICT_REPLACE);
  28. }
  29.  
  30. public String viewData(){
  31.  
  32. SQLiteDatabase db=foodCourt_loginData.getWritableDatabase(); //calling database to get writable data
  33. String[] cloumn={FoodCourt_LoginData.ID,FoodCourt_LoginData.USERNAME,FoodCourt_LoginData.USERPWD}; //stroing all the values in String array
  34. //Cursor is used to call the Stored data in Database and it starts data reading from row1 and moveToNext will call from upto end of data
  35. Cursor cursor=db.query(FoodCourt_LoginData.TABLENAME,cloumn,null,null,null,null,null);
  36. StringBuffer Buffer=new StringBuffer();
  37. while(cursor.moveToNext()){
  38. int cid=cursor.getInt(0);
  39. String Name=cursor.getString(1);
  40. String Password=cursor.getString(2);
  41. Buffer.append(cid+" "+Name+" "+Password+" "+"n");
  42. }
  43. return Buffer.toString();
  44. }
  45.  
  46. public String Login(String Uname){
  47. SQLiteDatabase db=foodCourt_loginData.getReadableDatabase();
  48. String[] column={FoodCourt_LoginData.USERNAME,FoodCourt_LoginData.USERPWD};
  49. Cursor cursor=db.query(FoodCourt_LoginData.TABLENAME,column,null,null,null,null,null);
  50. String a,b;
  51. b="not found";
  52. if(cursor.moveToFirst()){
  53. do {
  54. a=cursor.getString(0);
  55. b=cursor.getString(1);
  56. if(a.equals(Uname)){
  57. b=cursor.getString(1);
  58. break;
  59. }
  60. }while (cursor.moveToNext());
  61.  
  62. }
  63. return b;
  64. }
  65.  
  66. static class FoodCourt_LoginData extends SQLiteOpenHelper {
  67. private static final String DATABASE_NAME = "FOODCOURT_LOGINDATABASE.sqlite";
  68. private static final String TABLENAME = "FOODCOURT_LOGIN";
  69. private static final String ID = "id";
  70. private static final String USERNAME = "UserNAME";
  71. private static final String USERPWD = "UserPwd";
  72. private static final String USERADDRESS = "Address";
  73. private static final String USERMOBILE = "Mobile";
  74. private static final String USEREMAIL = "Email";
  75. private static final int DATABASE_VERSION=4;
  76. SQLiteDatabase db;
  77. private Context context;
  78. private static final String CreateTable = "CREATE TABLE IF NOT EXISTS "+TABLENAME+" ("+ID+" INTEGER PRIMARY KEY,"+ USERNAME + " VARCHAR(255) NOT NULL UNIQUE," + USERPWD + " VARCHAR(255)," + USERADDRESS + " VARCHAR(300)," + USERMOBILE + " INTEGER(10)," + USEREMAIL + " VARCHAR(30))";
  79. private static final String DropTable="DROP TABLE IF EXISTS '"+TABLENAME+"'";
  80. public FoodCourt_LoginData(Context context){
  81. super(context,DATABASE_NAME,null,DATABASE_VERSION);
  82. this.context=context;
  83. }
  84. @Override
  85. public void onCreate(SQLiteDatabase db) {
  86. try{
  87. db.execSQL(CreateTable);
  88. this.db=db;
  89. }catch (SQLException e){
  90. Message.message(context," "+e);
  91. }
  92.  
  93. }
  94.  
  95. @Override
  96. public void onUpgrade(SQLiteDatabase db, int i, int i1) {
  97. try {
  98. db.execSQL(DropTable);
  99. onCreate(db);
  100. }catch (SQLException e){
  101. Message.message(context," "+e);
  102. }
  103. }
  104. }
  105.  
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement