Java tutorial
//package com.java2s; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; public class Main { private static final String TABLE_SETTINGS = "Settings"; private static final String KEY_SETTINGS_ID = "id"; private static final String KEY_SETTINGS_KEY = "key"; private static final String KEY_SETTINGS_VALUE = "value"; public static int loadInteger(String key, int defaultVal, SQLiteDatabase db) { int ret; try { ret = Integer.parseInt(loadString(key, Integer.toString(defaultVal), db)); } catch (Exception ex) { ret = defaultVal; } return ret; } public static String loadString(String key, String defaultVal, SQLiteDatabase db) { String ret = defaultVal; if (db == null) return ret; Cursor cursor = db.query(TABLE_SETTINGS, new String[] { KEY_SETTINGS_ID, KEY_SETTINGS_KEY, KEY_SETTINGS_VALUE }, KEY_SETTINGS_KEY + "=?", new String[] { key }, null, null, null, null); if (cursor != null) { boolean moveFirst = cursor.moveToFirst(); if (moveFirst) ret = cursor.getString(2); } return ret; } }