Android examples for Database:Table Row Query
get Min Id from SQLiteDatabase table
import android.content.ContentValues; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; public class Main{ /*from w ww .jav a 2s . c o m*/ public static Long getMinId(SQLiteDatabase db, String tableName, String columnName) { Cursor c = null; c = getCursor(db, tableName, null, "select min(" + columnName + ") ", null, null, null, null, null); try { if (c.moveToNext()) { return c.getLong(c.getColumnIndex(columnName)); } else return null; } finally { if (c != null) c.close(); } } public static Cursor getCursor(SQLiteDatabase db, String sqlString, String[] selectionArgs) { return db.rawQuery(sqlString, selectionArgs); } public static Cursor getCursor(SQLiteDatabase db, String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit) { Cursor cursor = db.query(table, columns, selection, selectionArgs, groupBy, having, orderBy, limit); return cursor; } }