Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.work.dbtest;
- import android.content.ContentValues;
- import android.content.Context;
- import android.database.Cursor;
- import android.database.sqlite.SQLiteDatabase;
- import android.database.sqlite.SQLiteOpenHelper;
- /**
- * Created by Work on 25/03/2017.
- */
- public class MatchesDbHelper extends SQLiteOpenHelper {
- public static final String DATABASE_NAME = "Jobs2.db";
- public static final String TABLE_NAME = "job_table";
- public static final String ID = "ID";
- public static final String USERID = "USERID";
- public static final String JOBID = "JOBID";
- public MatchesDbHelper(Context context) {
- super(context, DATABASE_NAME, null, 1);
- }
- @Override
- public void onCreate(SQLiteDatabase db) {
- String CREATE_JOBS_TABLE = "CREATE TABLE " + TABLE_NAME + "("
- + ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + USERID + " TEXT,"
- + JOBID + " TEXT" + ")";
- db.execSQL(CREATE_JOBS_TABLE);
- }
- @Override
- public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
- onCreate(db);
- }
- public boolean insertData(String title, String role, String location, String description, String date, String hours, String pay, String skills){
- SQLiteDatabase db = this.getWritableDatabase();
- ContentValues contentValues = new ContentValues();
- contentValues.put(USERID, title);
- contentValues.put(JOBID, role);
- long result = db.insert(TABLE_NAME, null, contentValues);
- if(result == -1){
- return false;
- }
- else {
- return true;
- }
- }
- public Cursor getAllData(){
- SQLiteDatabase db = this.getWritableDatabase();
- Cursor res = db.rawQuery("select * from " + TABLE_NAME, null);
- return res;
- }
- //
- // public boolean updateData(String id, String title, String desc, String timePeriod, String salary, String skills){
- // SQLiteDatabase db = this.getWritableDatabase();
- // ContentValues contentValues = new ContentValues();
- // contentValues.put(ID, id);
- // contentValues.put(TITLE, title);
- // contentValues.put(DESC, desc);
- // contentValues.put(TIME_PERIOD, timePeriod);
- // contentValues.put(SALARY, salary);
- // contentValues.put(SKILLS_REQUIRED, skills);
- // db.update(TABLE_NAME, contentValues, "");
- // }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement