package com.example.sqliteprojects; import androidx.appcompat.app.AppCompatActivity; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); try{ SQLiteDatabase database = this.openOrCreateDatabase("MusiCians" , MODE_PRIVATE,null); database.execSQL("CREATE TABLE IF NOT EXISTS musicians (id INTEGER PRIMARY KEY , name VARCHAR , age INT)"); //database.execSQL("INSERT INTO musicians (name , age) VALUES ('Arown' , 50)");// //database.execSQL("INSERT INTO musicians (name , age) VALUES ('Mewzu' , 60)");// //database.execSQL("INSERT INTO musicians (name , age) VALUES ('Darrick' , 55)");// //database.execSQL("UPDATE musicians SET age = 61 WHERE name = 'Lars' ");// //database.execSQL("UPDATE musicians SET name = 'Darrick' WHERE id = 2 ");// //database.execSQL("DELETE FROM musicians WHERE id = 2");// //Cursor cursor = database.rawQuery("SELECT * FROM musicians WHERE Age = 52" , null );// Cursor cursor = database.rawQuery("SELECT * FROM musicians WHERE name LIKE 'A%'" , null ); //Cursor cursor = database.rawQuery("SELECT * FROM musicians" , null );// int nameIx = cursor.getColumnIndex("name"); int ageIx = cursor.getColumnIndex("age"); int idIx = cursor.getColumnIndex("id"); while (cursor.moveToNext()) { System.out.println("Name:" + cursor.getString(nameIx)); System.out.println("Age:" + cursor.getInt(ageIx)); System.out.println("id:" + cursor.getInt(idIx)); } cursor.close(); } catch (Exception e) { e.printStackTrace(); } } }