Mavzu: Ma’lumotlar bazasi


Download 9.22 Kb.
bet2/3
Sana22.06.2023
Hajmi9.22 Kb.
#1647339
1   2   3
Bog'liq
5-Mavzu

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'l

private static String DB_NAME = "cityinfo.db";

private static final int SCHEMA = 1; // ma'lumotlar bazasi versiyasi

static final String TABLE = "users"; // ma'lumotlar bazasidagi jadval nomi

// ustun nomlari

static 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;

}

@Override

public void onCreate(SQLiteDatabase db) { }

@Override

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { }


Download 9.22 Kb.

Do'stlaringiz bilan baham:
1   2   3




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling