Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. package com.lab10.faweks1.myapplication;
  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 Faweks1 on 16.01.2017.
  11. */
  12.  
  13. public class BazaAdresowa extends SQLiteOpenHelper {
  14. private static final int DATABASE_VERSION = 1;
  15. private static final String DATABASE_FILE = "BazaAdresowa.db";
  16. private static final String TABLE_NAME = "Osoby";
  17. private static final String TABLE_CREATE =
  18. "CREATE TABLE " + TABLE_NAME + " (" +
  19. "id integer primary key autoincrement," +
  20. "Imię text," +
  21. "Nazwisko text," +
  22. "Nr.tel text," +
  23. "E-mail text" +
  24. ");";
  25.  
  26. BazaAdresowa(Context context) {
  27. super(context, DATABASE_FILE, null, DATABASE_VERSION);
  28. }
  29.  
  30. @Override
  31. public void onCreate(SQLiteDatabase db) {
  32. db.execSQL(TABLE_CREATE);
  33. }
  34.  
  35. @Override
  36. public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  37.  
  38. }
  39.  
  40. public void addPerson(String imie, String nazwisko, String telefon, String mail){
  41. SQLiteDatabase db = getWritableDatabase();
  42. ContentValues values = new ContentValues();
  43. values.put("Imię", imie);
  44. values.put("Nazwisko", nazwisko);
  45. values.put("Nr.tel", telefon);
  46. values.put("E-mail", mail);
  47. db.insertOrThrow(TABLE_NAME, null, values);
  48. }
  49.  
  50. public Cursor getAllData(){
  51. String[] columns = {"Imię", "Nazwisko", "Nr.tel", "E-mail"};
  52. SQLiteDatabase db = getReadableDatabase();
  53. Cursor cursor = db.query(TABLE_NAME, columns, null, null, null, null, null);
  54. return cursor;
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement