需求:通过一个手机号可以查出手机号的归属地,网上是可以查的,但是10万个手机捏?当然你有1万个员工,每人帮你查10个,也算还可以。相形见绌,运用程序帮你查分分钟事情,接下来教大家如何用java批量查询手机归属地,当然代码还可以继续优化的,没有使用多线程,效率有所慢一些。
思路:excel读取——数据库查询手机归属地——excel写出
代码:
File f2003 = new File(filePath);
try {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
List<List<Object>> lists = _excelUtil.readExcel(f2003);
for(int i = 0;i<lists.size();i++){
String result02 = insertQuestions2ForExcel(lists.get(i),paperId,questionNoNum);
String[] result02_ = result02.split(",");
if(result02_.length == 4){
Map<String, Object> map = new HashMap<String, Object>();
map.put("CODEA", result02_[0]);
map.put("CODEB", result02_[1]);
map.put("CODEC", result02_[2]);
map.put("CODED", result02_[3]);
list.add(map);
}
}
/*final List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
List<List<Object>> lists = _excelUtil.readExcel(f2003);
ExecutorService executorService=Executors.newFixedThreadPool(10);
for(final List<Object> listss : lists){
executorService.execute(new Runnable() {
public synchronized void run() {
Map<String, Object> map = null;
String result02 = insertQuestions2ForExcel(listss,paperId,questionNoNum);
String[] result02_ = result02.split(",");
if(result02_.length == 4){
map = new HashMap<String, Object>();
map.put("CODEA", result02_[0]);
map.put("CODEB", result02_[1]);
map.put("CODEC", result02_[2]);
map.put("CODED", result02_[3]);
list.add(map);
}
}
});
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
executorService.shutdown();*/
LinkedHashMap<String, String> titleMap = new LinkedHashMap<String, String>();
titleMap.put("CODEA", "姓名");
titleMap.put("CODEB", "手机");
titleMap.put("CODEC", "省份");
titleMap.put("CODED", "城市");
FileOutputStream out = new FileOutputStream("D:/33.xls");
try {
_excelUtil.exportCommonExcel(null, titleMap, list, out);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("导出成功!");
} catch (IOException e) {
e.printStackTrace();
}