Frage

How to check if record exist with ImageName or not into database table, I am using below code to check that ?

// Check for Record using ImageName
    public boolean Exists(String strImageName) {
           SQLiteDatabase db;
           db = this.getReadableDatabase(); // Read Data
           Cursor cursor = db.rawQuery("select 1 from churchTable where ImageName=%s", 
                new String[] { strImageName });
           boolean exists = (cursor.getCount() > 0);
           cursor.close();
           return exists;
    }
War es hilfreich?

Lösung

Just replace %s with ? so the strImageName bind argument is used there:

Cursor cursor = db.rawQuery("select 1 from churchTable where ImageName=?", 
            new String[] { strImageName });
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top