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> getAreaByPid(int id, File file) {

        String sql = "select area,areaid  from area where cityid= " + id;
        SQLiteDatabase db = null;
        Cursor c = null;
        List<String> areaList = null;
        List areaIdList = null;
        Map<Integer, List> areaData = new HashMap<Integer, List>();
        try {
            db = SQLiteDatabase.openOrCreateDatabase(file, null);
            c = db.rawQuery(sql, null);
            areaList = new ArrayList<String>();
            areaIdList = new ArrayList<String>();

            while (c.moveToNext()) {
                Map areaMap = new HashMap();
                areaMap.put(c.getString(0), c.getInt(1));
                areaList.add(c.getString(0));
                areaIdList.add(areaMap);
            }
            areaData.put(0, areaList);
            areaData.put(1, areaIdList);
        } catch (Exception e) {
            Log.d("WineStock", "getAreaByPid:" + e.getMessage());
        } finally {
            if (c != null) {
                c.close();
            }
            if (db != null) {
                db.close();
            }
        }
        return areaData;
    }
}