1 |
torben |
593 |
package com.grundfos.gmatou.dataupload;
|
2 |
|
|
|
3 |
|
|
import java.io.IOException;
|
4 |
|
|
import javax.servlet.ServletException;
|
5 |
|
|
import javax.servlet.http.HttpServlet;
|
6 |
|
|
import javax.servlet.http.HttpServletRequest;
|
7 |
|
|
import javax.servlet.http.HttpServletResponse;
|
8 |
|
|
import java.sql.*;
|
9 |
|
|
import java.util.*;
|
10 |
|
|
|
11 |
|
|
public class DataViewer extends HttpServlet {
|
12 |
|
|
private static final long serialVersionUID = 1L;
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
public DataViewer() {
|
16 |
|
|
super();
|
17 |
|
|
}
|
18 |
|
|
|
19 |
|
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
20 |
|
|
try {
|
21 |
|
|
|
22 |
|
|
Connection conn = DBConnection.getDbConnection();
|
23 |
|
|
PreparedStatement stmt = conn.prepareStatement("SELECT id, date, device, length(data) FROM dataentries ORDER BY id" );
|
24 |
|
|
|
25 |
|
|
ResultSet rs = stmt.executeQuery();
|
26 |
|
|
|
27 |
|
|
ArrayList<DataBean> beans = new ArrayList<DataBean>();
|
28 |
|
|
while (rs.next())
|
29 |
|
|
{
|
30 |
|
|
DataBean bean = new DataBean();
|
31 |
|
|
bean.setId( rs.getInt(1) );
|
32 |
|
|
bean.setDate( rs.getTimestamp(2));
|
33 |
|
|
bean.setDevice( rs.getString(3));
|
34 |
|
|
bean.setDataSize( rs.getInt(4));
|
35 |
|
|
beans.add(bean);
|
36 |
|
|
}
|
37 |
|
|
|
38 |
|
|
rs.close();
|
39 |
|
|
stmt.close();
|
40 |
|
|
conn.close();
|
41 |
|
|
|
42 |
|
|
request.setAttribute("databeans", beans);
|
43 |
|
|
getServletContext().getRequestDispatcher("/dataviewer.jsp").forward(request,response);
|
44 |
|
|
|
45 |
|
|
} catch (Exception e) {
|
46 |
|
|
throw new ServletException(e);
|
47 |
|
|
}
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
}
|