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 JobsDbHelper extends SQLiteOpenHelper {
- public static final String DATABASE_NAME = "Jobs1.db";
- public static final String TABLE_NAME = "job_table";
- public static final String ID = "ID";
- public static final String TITLE = "TITLE";
- public static final String DESC = "DESCRIPTION";
- public static final String TIME_PERIOD = "TIMEPERIOD";
- public static final String SALARY = "SALARY";
- public static final String SKILLS_REQUIRED = "SKILLSREQUIRED";
- public JobsDbHelper(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," + TITLE + " TEXT,"
- + DESC + " TEXT," + TIME_PERIOD + " TEXT," + SALARY + " TEXT," + SKILLS_REQUIRED + " 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 description, String timePeriod, String salary, String skills){
- SQLiteDatabase db = this.getWritableDatabase();
- ContentValues contentValues = new ContentValues();
- contentValues.put(TITLE, title);
- contentValues.put(DESC, description);
- contentValues.put(TIME_PERIOD, timePeriod);
- contentValues.put(SALARY, salary);
- contentValues.put(SKILLS_REQUIRED, skills);
- 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