Advertisement
Guest User

Untitled

a guest
Jan 25th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. public static final String TAG = DBHelper.class.getSimpleName();
  2. public static final int DATEBASE_VERSION = 1;
  3. public static final String DATEBASE_NAME = "ContactDB";
  4. public static final String TABLE_CONTACT = "Contact";
  5.  
  6. public static final String KEY_ID = "ID";
  7. public static final String KEY_NAME = "Name";
  8. public static final String KEY_LOGIN = "Login";
  9. public static final String KEY_PASS = "Pass";
  10. public static int countUser = 0;
  11.  
  12. public DBHelper(Context context) {
  13. super(context, DATEBASE_NAME, null, DATEBASE_VERSION);
  14. }
  15.  
  16. public static final String CREATE_TABLE_USERS = "CREATE TABLE " + TABLE_CONTACT + " ( "
  17. + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
  18. + KEY_NAME + " TEXT, "
  19. + KEY_LOGIN + " TEXT, "
  20. + KEY_PASS + " TEXT);";
  21.  
  22.  
  23. @Override
  24. public void onCreate(SQLiteDatabase db) {
  25. db.execSQL(CREATE_TABLE_USERS);
  26. }
  27.  
  28. @Override
  29. public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  30. db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACT);
  31.  
  32. onCreate(db);
  33. }
  34.  
  35. @Override
  36. public void addContact(Contact contact) {
  37. SQLiteDatabase db = this.getWritableDatabase();
  38.  
  39. ContentValues value = new ContentValues();
  40. value.put(KEY_NAME, contact.getName());
  41. value.put(KEY_LOGIN, contact.getLogin());
  42. value.put(KEY_PASS, contact.getPass());
  43.  
  44. Long id = db.insert(TABLE_CONTACT, null, value);
  45. db.close();
  46.  
  47. Log.d(TAG, "user inserted" + id);
  48. countUser++;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement