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;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import java.io.File;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Main {
    public static Map<Integer, List> getCityByPid(int id, File file) {

        String sql = "select cityid,city  from city where provinceid= " + id;
        SQLiteDatabase db = null;
        Cursor c = null;
        Map<Integer, List> cityData = new HashMap<Integer, List>();
        //List cityList = null;
        try {
            db = SQLiteDatabase.openOrCreateDatabase(file, null);
            c = db.rawQuery(sql, null);
            List cityList1 = new ArrayList();
            List cityList2 = new ArrayList();
            while (c.moveToNext()) {
                Map cityMap = new HashMap();
                cityMap.put(c.getString(1), c.getInt(0));
                cityList1.add(cityMap);
                cityList2.add(c.getString(1));
            }
            cityData.put(0, cityList1);
            cityData.put(1, cityList2);

        } catch (Exception e) {
            Log.d("WineStock", "getCityByPid:" + e.getMessage());
        } finally {
            if (c != null) {
                c.close();
            }
            if (db != null) {
                db.close();
            }
        }
        return cityData;
    }
}