Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. package com.example.admin.androiddatabaseexample;
  2. import android.content.Context;
  3. import android.database.sqlite.SQLiteDatabase;
  4. import android.database.sqlite.SQLiteDatabase.CursorFactory;
  5. import android.database.sqlite.SQLiteOpenHelper;
  6. import android.util.Log;
  7. public class DataBaseHelper extends SQLiteOpenHelper {
  8. public DataBaseHelper(Context context, String name, CursorFactory factory, int version) {
  9. super(context, name, factory, version);
  10. }
  11. // Called when no database exists in disk and the helper class needs
  12. // to create a new one.
  13. @Override
  14. public void onCreate(SQLiteDatabase _db) {
  15. try {
  16. _db.execSQL(LoginDatabaseAdapter.DATABASE_CREATE);
  17. }catch(Exception er){
  18. Log.e("Error","exceptioin");
  19. }
  20. }
  21. // Called when there is a database version mismatch meaning that the version
  22. // of the database on disk needs to be upgraded to the current version.
  23. @Override
  24. public void onUpgrade(SQLiteDatabase _db, int _oldVersion, int _newVersion)
  25. {
  26. // Log the version upgrade.
  27. Log.w("TaskDBAdapter", "Upgrading from version " +_oldVersion + " to " +_newVersion + ", which will destroy all old data");
  28. // Upgrade the existing database to conform to the new version. Multiple
  29. // previous versions can be handled by comparing _oldVersion and _newVersion
  30. // values.
  31. // The simplest case is to drop the old table and create a new one.
  32. _db.execSQL("DROP TABLE IF EXISTS " + "LOGIN");
  33.  
  34. // Create a new one.
  35. onCreate(_db);
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement