query Scalar Float from sql query - Android Database

Android examples for Database:SQL Query

Description

query Scalar Float from sql query

Demo Code


//package com.java2s;

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

public class Main {
    public static Float queryScalarFloat(SQLiteDatabase database, String sql) {
        Cursor cursor = database.rawQuery(sql, null);
        if (cursor.moveToFirst()) {
            Float val = cursor.isNull(0) ? null : cursor.getFloat(0);
            cursor.close();/*w  ww  . jav a2  s.c  om*/
            return val;
        }
        cursor.close();
        return null;
    }
}

Related Tutorials