数据分析练习-3.12进度

今天完成了增加行政区划编码列和规范地域取值,学习了从百度API上根据地名获取准确地址和经度纬度的知识。

以下是学习内容:
部分源代码:

  1 package address;
  2 
  3 import address.Getregion;
  4 import address.DBUtil;
  5 
  6 import java.sql.Connection;
  7 import java.sql.ResultSet;
  8 import java.sql.Statement;
  9 import java.util.ArrayList;
 10 import java.util.List;
 11 
 12 public class Dao
 13 {
 14 
 15     int num_i=0;
 16     static List<String> ids=new ArrayList<String>();
 17     static List<String> names=new ArrayList<String>();
 18     public static void main(String[] args) {
 19 
 20         //select_co();
 21        // int i=0;
 22         
 23         select_city();
 24         select_ss();
 25     }
 26 
 27     public static List<String> select_city()
 28     {
 29         Connection conn = DBUtil.getConn();
 30         List<String> lists=new ArrayList<String>();
 31         String city=null;
 32         String str=new String();
 33         try {
 34             Statement state = conn.createStatement();
 35 
 36             ResultSet rs = state.executeQuery("select * from kjcg");
 37             while(rs.next()) {
 38                 //如果有结果,是认为是通过验证了
 39                 str=rs.getString("wcdw");
 40                 String newStr=str;
 41                 int i = str.indexOf(" ");
 42 
 43                 if(i!=-1)
 44                 {
 45                     System.out.println(str);
 46                     System.out.println(i);
 47                     newStr = str.substring(0,i);
 48                     System.out.println(newStr);
 49                 }
 50                // city=getregion.SELECT(newStr);
 51                 city=Getregion.SELECT1(newStr);
 52                 lists.add(city);
 53                 update_city(city,str);
 54             }
 55         } catch (Exception e)
 56         {
 57             e.printStackTrace();
 58         }
 59         return lists;
 60     }
 61 
 62   
 63     public static void update_city(String city,String value) {
 64 
 65        // String sql = "update kejichengguo1 set diyu ='"+city+"' where  wanchengdanwei ='"+value+"'";
 66         String sql = "update kjcg set xzqhbm ='"+city+"' where  wcdw ='"+value+"'";
 67         Connection conn = DBUtil.getConn();
 68         Statement state = null;
 69         try {
 70             state = conn.createStatement();
 71             state.executeUpdate(sql);
 72         } catch (Exception e) {
 73             e.printStackTrace();
 74         } finally {
 75             DBUtil.close(state, conn);
 76         }
 77     }
 78     public static List<String> select_ss()
 79     {
 80         Connection conn = DBUtil.getConn();
 81         List<String> lists=new ArrayList<String>();
 82         String city=null;
 83         String str=new String();
 84         try {
 85             Statement state = conn.createStatement();
 86 
 87             ResultSet rs = state.executeQuery("select * from kjcg");
 88             while(rs.next()) {
 89                 //如果有结果,是认为是通过验证了
 90                 str=rs.getString("wcdw");
 91                 String newStr=str;
 92                 int i = str.indexOf(" ");
 93 
 94                 if(i!=-1)
 95                 {
 96                     System.out.println(str);
 97                     System.out.println(i);
 98                     newStr = str.substring(0,i);
 99                     System.out.println(newStr);
100                 }
101                // city=getregion.SELECT(newStr);
102                 city=Getregion.SELECT(newStr);
103                 lists.add(city);
104                 update_ss(city,str);
105             }
106         } catch (Exception e)
107         {
108             e.printStackTrace();
109         }
110         return lists;
111     }
112     public static void update_ss(String city,String value) {
113 
114         // String sql = "update kejichengguo1 set diyu ='"+city+"' where  wanchengdanwei ='"+value+"'";
115          String sql = "update kjcg set ss ='"+city+"' where  wcdw ='"+value+"'";
116          Connection conn = DBUtil.getConn();
117          Statement state = null;
118          try {
119              state = conn.createStatement();
120              state.executeUpdate(sql);
121          } catch (Exception e) {
122              e.printStackTrace();
123          } finally {
124              DBUtil.close(state, conn);
125          }
126      }
127 }

 运行截图:

数据库中数据展示:

地域规范

 行政区划编码

 遇到的问题:

根据完成单位名称到百度地图API中获取规范地址和行政编码时,有的完成单位地名在百度地图中找不到,使得返回值为空。

猜你喜欢

转载自www.cnblogs.com/lover995/p/12483120.html