Example usage for android.database Cursor getString

List of usage examples for android.database Cursor getString

Introduction

In this page you can find the example usage for android.database Cursor getString.

Prototype

String getString(int columnIndex);

Source Link

Document

Returns the value of the requested column as a String.

Usage

From source file:Main.java

private static String readString(Cursor cursor, int index) {
    return (cursor.isNull(index) ? null : cursor.getString(index));
}

From source file:Main.java

/**
 * Retrieves a {@link String} value from the {@link Cursor}.
 * //from  ww  w  .  j ava  2  s . c om
 * @param cursor
 *            The {@link Cursor} pointing at the correct record.
 * @param strColName
 *            The name of the column to retrieve.
 * @return A {@link String} containing the value.
 */
public static String getString(final Cursor cursor, final String strColName) {
    String strResult = cursor.getString(cursor.getColumnIndex(strColName));
    if (strResult == null)
        strResult = "";

    return strResult;
}

From source file:Main.java

public static String buildFullName(Cursor cursor, int firstNameIndex, int lastNameIndex) {
    String firstName = cursor.getString(firstNameIndex);
    String lastName = cursor.getString(lastNameIndex);
    return buildFullName(firstName, lastName);
}

From source file:Main.java

private static ArrayList<String> readStrings(SQLiteDatabase db, String query, int colIdx) {
    ArrayList<String> rows = new ArrayList<String>();
    Cursor c = db.rawQuery(query, null);
    while (c.moveToNext()) {
        rows.add(c.getString(colIdx));
    }/*from  w  w  w .  j  a v a  2  s .c o  m*/
    c.close();
    return rows;
}

From source file:com.codebutler.farebot.key.CardKeys.java

private static CardKeys fromCursor(Cursor cursor) throws JSONException {
    String cardType = cursor.getString(cursor.getColumnIndex(KeysTableColumns.CARD_TYPE));
    String keyData = cursor.getString(cursor.getColumnIndex(KeysTableColumns.KEY_DATA));

    JSONObject keyJSON = new JSONObject(keyData);

    if (cardType.equals("MifareClassic")) {
        return ClassicCardKeys.fromJSON(keyJSON);
    }//www  .  j a v a2  s.  c  o m

    throw new IllegalArgumentException("Unknown card type for key: " + cardType);
}

From source file:Main.java

public static boolean isTableExists(SQLiteDatabase db, String tableName) {
    String sql = "SELECT name FROM sqlite_master WHERE type = 'table' AND name = ? ";
    String paras[] = { tableName };
    try {/*from  w ww . ja v  a 2s  . com*/
        Cursor cursor = db.rawQuery(sql, paras);
        cursor.moveToNext();
        String name = cursor.getString(cursor.getColumnIndex("name"));
        if (name.equals(tableName)) {
            return true;
        } else {
            return false;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:Main.java

public static ArrayList<String> queryDay(SQLiteDatabase db) {
    ArrayList<String> dayList = new ArrayList<String>();

    String sqlStr = "select distinct date from " + TABLE_NAME + " order by _id desc";

    Cursor cursor = db.rawQuery(sqlStr, null);

    while (cursor.moveToNext()) {
        dayList.add(cursor.getString(0));
    }/* w ww .  j av a 2 s. c o  m*/

    return dayList;
}

From source file:Main.java

public static String stringFromCursor(Cursor c, String field) {
    if (c.isNull(c.getColumnIndex(field))) {
        return null;
    }//from  w w  w . j a va  2 s.  c o  m
    return c.getString(c.getColumnIndex(field));
}

From source file:Main.java

public static String getCursorString(Cursor cursor, String name) {
    if (isCursorEmpty(cursor)) {
        return "";
    } else {/*from  www. ja v a  2 s  . c o  m*/
        return cursor.getString(cursor.getColumnIndex(name));
    }
}

From source file:Main.java

public static String getStringFromCursor(final Cursor cur, final String column) {
    final int idx = cur.getColumnIndex(column);
    return (idx == -1) ? null : cur.getString(idx);
}