Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.lab10.faweks1.myapplication;
- import android.content.ContentValues;
- import android.content.Context;
- import android.database.Cursor;
- import android.database.sqlite.SQLiteDatabase;
- import android.database.sqlite.SQLiteOpenHelper;
- /**
- * Created by Faweks1 on 16.01.2017.
- */
- public class BazaAdresowa extends SQLiteOpenHelper {
- private static final int DATABASE_VERSION = 1;
- private static final String DATABASE_FILE = "BazaAdresowa.db";
- private static final String TABLE_NAME = "Osoby";
- private static final String TABLE_CREATE =
- "CREATE TABLE " + TABLE_NAME + " (" +
- "id integer primary key autoincrement," +
- "Imię text," +
- "Nazwisko text," +
- "Nr.tel text," +
- "E-mail text" +
- ");";
- BazaAdresowa(Context context) {
- super(context, DATABASE_FILE, null, DATABASE_VERSION);
- }
- @Override
- public void onCreate(SQLiteDatabase db) {
- db.execSQL(TABLE_CREATE);
- }
- @Override
- public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- }
- public void addPerson(String imie, String nazwisko, String telefon, String mail){
- SQLiteDatabase db = getWritableDatabase();
- ContentValues values = new ContentValues();
- values.put("Imię", imie);
- values.put("Nazwisko", nazwisko);
- values.put("Nr.tel", telefon);
- values.put("E-mail", mail);
- db.insertOrThrow(TABLE_NAME, null, values);
- }
- public Cursor getAllData(){
- String[] columns = {"Imię", "Nazwisko", "Nr.tel", "E-mail"};
- SQLiteDatabase db = getReadableDatabase();
- Cursor cursor = db.query(TABLE_NAME, columns, null, null, null, null, null);
- return cursor;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement