Mavzu: Ma’lumotlar bazasi
Download 9.22 Kb.
|
5-Mavzu
- Bu sahifa navigatsiya:
- Va keyin malumotlar bazasini unga nusxalash
- @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { }
Jadvalni yaratgandan so'ng, assets papkasini Android Studio dagi loyihaga va yangi yaratilgan ma'lumotlar bazasini assets papkaiga qo'shing. Buning uchun loyihaning to'liq ta'rifiga o'ting, main papkani o'ng tugmasini bosing va menyudan New->Directory ni tanlang:Keyin, paydo bo'lgan oynada jild nomini kiriting - assets:Va keyin ma'lumotlar bazasini unga nusxalash:Menimcha, ma'lumotlar bazasi "cityinfo.db" deb nomlanadi. DatabaseHelper kodini quyidagicha o'zgartiramiz:Menimcha, ma'lumotlar bazasi "cityinfo.db" deb nomlanadi. DatabaseHelper kodini quyidagicha o'zgartiramiz:package com.example.sqliteapp;import android.database.SQLException;import android.database.sqlite.SQLiteOpenHelper;import android.database.sqlite.SQLiteDatabase;import android.content.Context;import android.util.Log;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;class DatabaseHelper extends SQLiteOpenHelper {private static String DB_PATH; // ma'lumotlar bazasiga to'liq yo'lprivate static String DB_NAME = "cityinfo.db";private static final int SCHEMA = 1; // ma'lumotlar bazasi versiyasistatic final String TABLE = "users"; // ma'lumotlar bazasidagi jadval nomi// ustun nomlaristatic final String COLUMN_ID = "_id";static final String COLUMN_NAME = "name";static final String COLUMN_YEAR = "year";private Context myContext; DatabaseHelper(Context context) {super(context, DB_NAME, null, SCHEMA);this.myContext=context;DB_PATH =context.getFilesDir().getPath() + DB_NAME;}@Overridepublic void onCreate(SQLiteDatabase db) { }@Overridepublic void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { }Download 9.22 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling