public void onClick(View view) {
SQLiteDatabase db = getBaseContext().openOrCreateDatabase("app.db", MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS users (ismi TEXT, yoshi INTEGER)");
db.execSQL("INSERT INTO users VALUES ('Alisher', 24);");
db.execSQL("INSERT INTO users VALUES ('Bahrom', 30);");
Cursor query = db.rawQuery("SELECT * FROM users;", null);
TextView textView = findViewById(R.id.text_view);
if (query.moveToFirst()) {
do {
String ismi = query.getString(0);
int yoshi = query.getInt(1);
textView.append("Ismi: " + ismi + " Yoshi: " + yoshi + "\n");
}
while (query.moveToNext());
}
query.close();
db.close();
}
}
Bu ilovadagi tugmani bosish bilan avval app.db ma'lumotlar bazasida users yangi jadvali yaratiladi, so'ngra unga INSERT yordamida ma'lumotlar bazasiga ikkita ob'ekt qo'shiladi.
Keyinchalik, SELECT yordamida barcha qo'shilgan foydalanuvchilarni ma'lumotlar bazasidan Cursor kursori ko'rinishida olamiz.