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> getProvince(File file) {

        String sql = "select provinceid ,province from province ";
        SQLiteDatabase db = null;
        Cursor c = null;
        Map<Integer, List> provinceData = new HashMap<Integer, List>();
        //List provinceList = null;
        try {
            db = SQLiteDatabase.openOrCreateDatabase(file, null);
            c = db.rawQuery(sql, null);
            List provinceList1 = new ArrayList();
            List provinceList2 = new ArrayList();
            while (c.moveToNext()) {
                Map provinceMap = new HashMap();
                provinceMap.put(c.getString(1), c.getInt(0));
                provinceList1.add(provinceMap);
                provinceList2.add(c.getString(1));
            }
            provinceData.put(0, provinceList1);
            provinceData.put(1, provinceList2);
        } catch (Exception e) {
            Log.d("WineStock", "getProvince:" + e.getMessage());
        } finally {
            if (c != null) {
                c.close();
            }
            if (db != null) {
                db.close();
            }
        }
        return provinceData;
    }
}