通过IntentService读取收获地址省市县信息存入数据库

public class MyIntentService extends IntentService {


   public MyIntentService() {
      super("");
      // TODO Auto-generated constructor stub
   }

   public MyIntentService(String name) {
      super(name);
      // TODO Auto-generated constructor stub
   }

   @Override
   protected void onHandleIntent(Intent intent) {
      // TODO Auto-generated method stub

      try {
         // TODO Auto-generated method stub

         MyDBHelper db = MyDBHelper.getHelper(this);

         ArrayList<RecieverInfo>pro = db.queryProvinceAddress();

         if(pro==null||pro.isEmpty()){

            try {
               db.open();
               db.getDB().beginTransaction();
               InputStream is = getAssets().open("express_address.txt");
               BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
               String inputLine = null;//拼接sql 将收获地址 1,福建省,1,福州市,2,鼓楼区 存入
               String insertSqlString = "insert into  "+MyDBHelper.TABLE_ADDRESS+"  values(";
               while ((inputLine = reader.readLine()) != null) {
                  inputLine=inputLine.replaceAll(",", "','");
                  db.execSQL(MyDBHelper.TABLE_ADDRESS,insertSqlString+"'"+inputLine+"');");  
               }

               is.close();
               reader.close();
	       db.getDB().setTransactionSuccessful();
} catch (Exception e) { e.printStackTrace(); }finally{ if(db!=null){ db.getDB().endTransaction(); db.close(); db = null; } } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
/**
 *数据库收货人地址
 *
 */
public class RecieverInfo implements Serializable {
   
   private static final long serialVersionUID = -5983376232579275894L;
   
   private String province_id;
    private String province_name;
    private String city_id;
    private String city_name;
    private String county_id;
    private String county_name;

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值