Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.database.Cursor;

public class Main {
    /**
     * Gets the column data, returns a String
     *
     * @param cursor
     * @param columnName
     * @return
     */
    private static String getColumnData(Cursor cursor, String columnName) {
        if (cursor == null) {
            return null;
        }
        if (isValidColumn(cursor, columnName)) {
            try {
                String str = cursor.getString(cursor.getColumnIndex(columnName));
                return str;

            } catch (Exception e) {
                return null;
            }
        } else {
            return null;
        }
    }

    /**
     * Checks if it is a valid column within the cursor data
     *
     * @param cursor
     * @param columnName
     * @return
     */
    private static boolean isValidColumn(Cursor cursor, String columnName) {
        int x = cursor.getColumnIndex(columnName);
        if (x < 0) {
            //No column matches that, it doesn't exist
            return false;
        } else {
            //A column matches that, it exists
            return true;
        }
    }
}