【Java】 批处理
来源:互联网 发布:windows邮件服务器搭建 编辑:程序博客网 时间:2024/06/05 09:50
//用的是和风天气的API,先把JSON的数据存放到results数组
String dituUrl =" https://api.heweather.com/x3/condition?search=allcond&key=df5dbde555e54a788d1edd1c0ec09c1f";
String currentline = "";
String totalstring = "";
URL url = new URL(dituUrl);
HttpURLConnection connection = (HttpURLConnection) url
.openConnection();
connection.connect();
InputStream urlStream = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(
urlStream, "UTF-8"));
while ((currentline = reader.readLine()) != null) {
totalstring += currentline + "\r\n";
}
JSONObject json = JSON.parseObject(totalstring);
String code = json.getString("status");
long startTime = new Date().getTime();
if ("ok".equals(code)) {
JSONArray results = json.getJSONArray("cond_info");
//开始进入批处理的操作,将数据批处理存到t_b_weather_condition中
System.out.print(results.size());
PreparedStatement ps = null;
String sql = "insert into t_b_weather_condition(weather_code,weather_desc,weather_desc_en,weather_icon) values (?,?,?,?)";
Connection con = ConnectionFactory.getConnection();
ps = con.prepareStatement(sql);
for (int i=0;i<results.size();i++) {
JSONObject obj = results.getJSONObject(i);
ps.setInt(1, obj.getInteger("code"));
ps.setString(2, obj.getString("txt"));
ps.setString(3, obj.getString("txt_en"));
ps.setString(4, obj.getString("icon"));
ps.addBatch();
// System.out.println(results.getJSONObject(i));
}
ps.executeBatch();
ps.close();
con.close();
long endTime = new Date().getTime();
System.out.println(endTime - startTime + "秒");
}
return ;
0 0
- java 批处理
- java批处理
- Java批处理
- 【Java】 批处理
- java批处理
- java运行批处理命令
- 批处理(Java)
- sql java 批处理
- 批处理配置JAVA环境变量
- java自动编译批处理
- java环境变量批处理
- 批处理调用java类
- java程序做成批处理
- Java JDBC 批处理
- Java调用批处理程序
- java中批处理
- Java -- JDBC 批处理
- Java批处理操作
- C语言实现区块加密
- String和StringBuffer的区别
- mysql实现随机获取几条数据的方法
- hdu 1698 Just a Hook(线段树区间覆盖)
- grafana安装,与zabbix结合使用监控mysql
- 【Java】 批处理
- quick实现虚拟摇杆
- nyoj 489
- TBB之Timing
- 解题报告:POJ_1703Find them, Catch them 并查集
- 《数据库索引设计优化》读书笔记(六)
- 百度地图再次签名报230错误
- POJ1001 高精度乘法
- 程序相关的免费视频的网站9秒