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;
}