Java tutorial
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import android.content.ContentValues; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; public class Main { public static final String TABLE_NAME = "dqxx"; public static ArrayList<ContentValues> getCity(SQLiteDatabase db, int dqx_dqxx01, boolean municipalities) { ArrayList<ContentValues> list = new ArrayList<ContentValues>(); ContentValues values = null; Cursor cursor = db.query(TABLE_NAME, new String[] { "DQXX01", "DQXX02" }, "DQX_DQXX01=?", new String[] { "" + dqx_dqxx01 }, null, null, "DQXX01 ASC"); if (cursor != null) { if (municipalities) { cursor.moveToNext(); } while (cursor.moveToNext()) { values = new ContentValues(); values.put("city_id", cursor.getInt(0)); values.put("city", cursor.getString(1)); list.add(values); } } if (cursor != null && !cursor.isClosed()) { cursor.close(); } return list; } }