Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. package com.example.work.dbtest;
  2.  
  3. import android.content.ContentValues;
  4. import android.content.Context;
  5. import android.database.Cursor;
  6. import android.database.sqlite.SQLiteDatabase;
  7. import android.database.sqlite.SQLiteOpenHelper;
  8.  
  9. /**
  10. * Created by Work on 25/03/2017.
  11. */
  12.  
  13. public class MatchesDbHelper extends SQLiteOpenHelper {
  14.  
  15. public static final String DATABASE_NAME = "Jobs2.db";
  16. public static final String TABLE_NAME = "job_table";
  17. public static final String ID = "ID";
  18. public static final String USERID = "USERID";
  19. public static final String JOBID = "JOBID";
  20.  
  21. public MatchesDbHelper(Context context) {
  22. super(context, DATABASE_NAME, null, 1);
  23. }
  24.  
  25. @Override
  26. public void onCreate(SQLiteDatabase db) {
  27. String CREATE_JOBS_TABLE = "CREATE TABLE " + TABLE_NAME + "("
  28. + ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + USERID + " TEXT,"
  29. + JOBID + " TEXT" + ")";
  30. db.execSQL(CREATE_JOBS_TABLE);
  31. }
  32.  
  33. @Override
  34. public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  35. db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
  36. onCreate(db);
  37. }
  38.  
  39. public boolean insertData(String title, String role, String location, String description, String date, String hours, String pay, String skills){
  40. SQLiteDatabase db = this.getWritableDatabase();
  41. ContentValues contentValues = new ContentValues();
  42. contentValues.put(USERID, title);
  43. contentValues.put(JOBID, role);
  44. long result = db.insert(TABLE_NAME, null, contentValues);
  45. if(result == -1){
  46. return false;
  47. }
  48. else {
  49. return true;
  50. }
  51. }
  52.  
  53. public Cursor getAllData(){
  54. SQLiteDatabase db = this.getWritableDatabase();
  55. Cursor res = db.rawQuery("select * from " + TABLE_NAME, null);
  56. return res;
  57. }
  58. //
  59. // public boolean updateData(String id, String title, String desc, String timePeriod, String salary, String skills){
  60. // SQLiteDatabase db = this.getWritableDatabase();
  61. // ContentValues contentValues = new ContentValues();
  62. // contentValues.put(ID, id);
  63. // contentValues.put(TITLE, title);
  64. // contentValues.put(DESC, desc);
  65. // contentValues.put(TIME_PERIOD, timePeriod);
  66. // contentValues.put(SALARY, salary);
  67. // contentValues.put(SKILLS_REQUIRED, skills);
  68. // db.update(TABLE_NAME, contentValues, "");
  69. // }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement