1012每日博客

继续昨天的那一道题目,其中的一问是:

汇总统计 9 月 1 日到 9 月 15 日之间各个代理商的销售利润。
编号,卖出方代码,买入数量,买入金额,卖出数量,卖出金额,销售利润(卖出
金额-买入金额)
这个也是先从HIVE进行数据分析,然后将数据存储在一个新的表里,然后将这个表的数据导出到MySQL,并且用echars展示,需要做的就是先从数据库读取信息,如下:
public List<FourBean> FourAllData(){
List<FourBean> list=new ArrayList<>();
FourBean bean=null;
String sql="select * from jieguo where sale_nbr like '%O11%'";
Connection conn =Dbutil.getConnection();
Statement st=null;
ResultSet rs=null;
try {
st=conn.createStatement();
st.executeQuery(sql);
rs=st.executeQuery(sql);
while(rs.next()) {
String day_id=rs.getString("day_id");
String sale_nbr=rs.getString("sale_nbr");
String incnt=rs.getString("incnt");
String inround=rs.getString("inround");
String outcnt=rs.getString("outcnt");
String outround=rs.getString("outround");
String li=rs.getString("li");
bean=new FourBean(day_id,sale_nbr,incnt,inround,outcnt,outround,li);
list.add(bean);

}
} catch (SQLException e) {
e.printStackTrace();
}
finally{
Dbutil.close(st, conn);
}
return list;
}
我这里写的是获取第四个数据表的信息,然后将其以List的形式传递给servlet,然后servlet在发送到前台,
servlet代码如下:
public void getAlldata(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=UTF-8");
List<FourBean> list=dao.FourAllData();
JSONArray json=new JSONArray();
for(int i=0;i<list.size();i++){
JSONObject ob=new JSONObject();
ob.put("day_id",list.get(i).getDay_id());
ob.put("sale_nbr",list.get(i).getSale_nbr());
ob.put("incnt",list.get(i).getIncnt());
ob.put("inround",list.get(i).getInround());
ob.put("outcnt",list.get(i).getOutcnt());
ob.put("outround",list.get(i).getOutround());
ob.put("li",list.get(i).getLi());
json.add(ob);
}
PrintWriter out = response.getWriter();
out.write(json.toString());

}
然后这个方法就将数据发送给了前端,其中的JOSN是
net.sf.json.JSONArray;

net.sf.json.JSONObject;

原文地址:https://www.cnblogs.com/ruangongwangxiansheng/p/14161745.html