1 |
torben |
279 |
package dk.thoerup.droidradarservice; |
2 |
|
|
|
3 |
|
|
import java.io.IOException; |
4 |
|
|
import java.sql.Connection; |
5 |
|
|
import java.sql.ResultSet; |
6 |
|
|
import java.sql.SQLException; |
7 |
|
|
import java.sql.Statement; |
8 |
|
|
import java.util.ArrayList; |
9 |
|
|
import java.util.List; |
10 |
|
|
|
11 |
|
|
import javax.servlet.ServletException; |
12 |
|
|
import javax.servlet.http.HttpServlet; |
13 |
|
|
import javax.servlet.http.HttpServletRequest; |
14 |
|
|
import javax.servlet.http.HttpServletResponse; |
15 |
|
|
|
16 |
|
|
|
17 |
|
|
/** |
18 |
|
|
* Servlet implementation class ViewDroidLocations |
19 |
|
|
*/ |
20 |
|
|
public class ViewDroidLocations extends HttpServlet { |
21 |
|
|
private static final long serialVersionUID = 1L; |
22 |
|
|
|
23 |
|
|
/** |
24 |
|
|
* @see HttpServlet#HttpServlet() |
25 |
|
|
*/ |
26 |
|
|
public ViewDroidLocations() { |
27 |
|
|
super(); |
28 |
|
|
// TODO Auto-generated constructor stub |
29 |
|
|
} |
30 |
|
|
|
31 |
|
|
/** |
32 |
|
|
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) |
33 |
|
|
*/ |
34 |
|
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
35 |
|
|
Connection conn = null; |
36 |
|
|
ResultSet rs = null; |
37 |
|
|
try |
38 |
|
|
{ |
39 |
|
|
conn = DBConnection.getConnection(); |
40 |
|
|
|
41 |
|
|
Statement stmt = conn.createStatement(); |
42 |
|
|
rs = stmt.executeQuery("SELECT imei,handle,groupname,latitude,longitude,updated FROM droidradar ORDER BY updated ASC"); |
43 |
|
|
|
44 |
|
|
List<DroidBean> droids = new ArrayList<DroidBean>(); |
45 |
|
|
while (rs.next()) { |
46 |
|
|
DroidBean bean = new DroidBean(); |
47 |
|
|
bean.setImei( rs.getLong(1) ); |
48 |
|
|
bean.setHandle( rs.getString(2) ); |
49 |
|
|
bean.setGroup(rs.getString(3)); |
50 |
|
|
bean.setLatitude(rs.getDouble(4)); |
51 |
|
|
bean.setLongitude(rs.getDouble(5)); |
52 |
|
|
bean.setLastUpdate(rs.getTimestamp(6)); |
53 |
|
|
|
54 |
|
|
droids.add(bean); |
55 |
|
|
|
56 |
|
|
} |
57 |
|
|
request.setAttribute("droids", droids); |
58 |
|
|
|
59 |
|
|
|
60 |
|
|
} catch (Exception e) { |
61 |
|
|
throw new ServletException(e); |
62 |
|
|
} finally { |
63 |
|
|
try{ |
64 |
|
|
if (rs != null && !rs.isClosed()) |
65 |
|
|
rs.close(); |
66 |
|
|
if (conn != null && !conn.isClosed() ) |
67 |
|
|
conn.close(); |
68 |
|
|
} catch (SQLException e) {} |
69 |
|
|
} |
70 |
|
|
getServletContext().getRequestDispatcher("/ViewDroidLocations.jsp").forward(request,response); |
71 |
|
|
} |
72 |
|
|
|
73 |
|
|
} |