每日日报2021.9.29

完成内容:

1.编写2019 级课堂测试试卷-HIVE 数据分析

echart

listbean

package echart;

public class listBean {
private String name;
private int num;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getNum() {
return num;
}

public void setNum(int num) {
this.num = num;
}
}
listdao
package echart;


import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

public class listDao {
public ArrayList<listBean> select_all(String table_name){ //返回值为ArrayList的方法
Connection conn=null;
Statement stmt = null;
ResultSet rst = null;
String sql=null;
try {
conn= listUtil.getConncetion();
stmt=conn.createStatement();
if(table_name=="zhu"){
sql = "select * from list";
}

System.out.println("查询成功");
rst=stmt.executeQuery(sql); //将查询到的结果集保存到ResultSet实例化对象rst中

ArrayList<listBean> array = new ArrayList<listBean>(); //创建一个ArrayList对象
while(rst.next()){ //通过循环将rst对象中的数据存到array中
listBean bar = new listBean();
bar.setName(rst.getString("name")); //name对应数据库中的name
bar.setNum(rst.getInt("num")); //number对应数据库中的number
array.add(bar);
}
stmt.close();
rst.close();
conn.close();
return array; // 将存有数据库数据的array对象作为返回值
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println("读取失败");
return new ArrayList<listBean>();
}

}
}
listutil
package echart;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class listUtil {
public static Connection getConncetion(){
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/xinwen?useUnicode=true&characterEncoding=utf-8";
String user="root";
String password="123456";
conn=DriverManager.getConnection(url, user, password); //执行数据库连接方法
System.out.println("连接成功");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("连接失败");
e.printStackTrace();
}
return conn;

}

}
zhuservlet
package echart;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet(name = "zhuServlet", value = "/zhuServlet")
public class zhuServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
listDao listDao = new listDao();
ArrayList<listBean> list = listDao.select_all("zhu");
JSONArray json=new JSONArray();
for(int i=0;i<list.size();i++) {
JSONObject ob=new JSONObject();
ob.put("name", list.get(i).getName());
ob.put("num", list.get(i).getNum());

json.add(ob);
System.out.println("json数据转换成功");
}
System.out.println(json);
response.setContentType("text/html; charset=utf-8");
response.getWriter().write(json.toString()); //将json数据返回给客户端

}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

}
}
echart。jsp
<!DOCTYPE html>
<html lang="en">
<head>
<title>Title</title>
<meta charset="utf-8">

<script type="text/javascript" src="js/echarts.js"></script>

</head>
<body>
<!-- 为ECharts准备一个具备大小(宽高)的Dom -->
<div id="main" style="width: 600px;height:400px;"></div>
<script type="text/javascript">

// <%--var arr=new Array();--%>
// <%--var index=0;--%>
// <%--<c:forEach items="${sessionScope.users}" var="user" varStatus="s">arr[index++]=${user.number};</c:forEach>--%>
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));

// 指定图表的配置项和数据
var option = {
title: {
text: '',
// subtext: 'Fake Data',
left: 'center'
},
tooltip: {
trigger: 'item'
},
legend: {
orient: 'vertical',
left: 'left'
},
series: [
{
name: 'Access From',
type: 'pie',
radius: '50%',
data: [
{ value: 19, name: '' },
{ value: 29, name: '' },
{ value: 26, name: '' },
{ value: 11, name: '' },
],
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
};

// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
</script>
</body>
<html>

 

 

 

 

遇到问题:
 无
目标:继续学习hadoop
posted @ 2021-09-29 11:44  1905-1雷宇  阅读(54)  评论(0编辑  收藏  举报