Code example for SQLiteStatement

Methods: bindString, executeInsert

0
 
    public void insert(Person person){
        SQLiteDatabase db = getWritableDatabase();
        SQLiteStatement stmt = db.compileStatement("insert into "+TABLE_NAME+
                " (" + PERSON_NAME_COL +  ","+CONTACT_NUMBER_COL+ ","+ADDRESS_COL+","+ BLOOD_GROUP_COL +") values ( ?,?,?,? );");
        stmt.bindString(1,person.getName());
        stmt.bindString(2,person.getContactNumber());
        stmt.bindString(3, person.getAddress());
        stmt.bindString(4, person.getBloodGroup());
        stmt.executeInsert();
        Cursor cursor = db.query(TABLE_NAME, new String[]{PERSON_NAME_COL}, null, null, null, null, null);
        cursor.moveToFirst();
        System.out.println("*************"+cursor.getString(0));
    } 
 
    public void getDonorInfo(String bloodGroup, String Location){
        SQLiteDatabase db = getReadableDatabase();
 
//        SQLiteStatement stmt = db.compileStatement("select * from "+TABLE_NAME+ "where" + BLOOD_GROUP_COL + "=" + bloodGroup + ";"); 
    }