query Scalar Int from database sql query - Android Database

Android examples for Database:SQL Query

Description

query Scalar Int from database sql query

Demo Code


//package com.java2s;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class Main {
    public static Integer queryScalarInt(SQLiteDatabase database, String sql) {
        Cursor cursor = database.rawQuery(sql, null);
        if (cursor.moveToFirst()) {
            Integer val = cursor.isNull(0) ? null : cursor.getInt(0);
            cursor.close();/*from ww w .j  av a  2  s .c  o m*/
            return val;
        }
        cursor.close();
        return null;
    }
}

Related Tutorials