13 |
|
|
14 |
public class DumpResultSet extends HttpServlet { |
public class DumpResultSet extends HttpServlet { |
15 |
|
|
16 |
|
public DumpResultSet() { |
17 |
|
super(); |
18 |
|
} |
19 |
|
|
20 |
|
|
21 |
private static final long serialVersionUID = 1L; |
private static final long serialVersionUID = 1L; |
22 |
|
|
26 |
Connection conn = null; |
Connection conn = null; |
27 |
Statement stmt = null; |
Statement stmt = null; |
28 |
ResultSet rs = null; |
ResultSet rs = null; |
29 |
|
|
30 |
try { |
try { |
31 |
|
int count = 0; |
32 |
|
|
33 |
conn = DBConnection.getConnection(); |
conn = DBConnection.getConnection(); |
34 |
stmt = conn.createStatement(); |
stmt = conn.createStatement(); |
35 |
|
|
38 |
int columns = meta.getColumnCount(); |
int columns = meta.getColumnCount(); |
39 |
|
|
40 |
sb.append("<h2>").append(sql).append("</h2>"); |
sb.append("<h2>").append(sql).append("</h2>"); |
41 |
sb.append("<table><tr>"); |
sb.append("<table border=1><tr>"); |
42 |
for (int i=1; i<=columns; i++) { |
for (int i=1; i<=columns; i++) { |
43 |
sb.append("<th>").append( meta.getColumnName(i)).append("</th>"); |
sb.append("<th>").append( meta.getColumnName(i)).append("</th>"); |
44 |
} |
} |
45 |
sb.append("</tr>"); |
sb.append("</tr>\n\n"); |
46 |
while(rs.next()) |
while(rs.next()) |
47 |
{ |
{ |
48 |
|
count++; |
49 |
|
|
50 |
sb.append("<tr>"); |
sb.append("<tr>"); |
51 |
for (int i=1; i<=columns; i++) { |
for (int i=1; i<=columns; i++) { |
52 |
sb.append("<td>").append(rs.getString(i)).append("</td>"); |
sb.append("<td>").append(rs.getString(i)).append("</td>"); |
53 |
} |
} |
54 |
sb.append("</tr>"); |
sb.append("</tr>\n"); |
55 |
} |
} |
56 |
sb.append("</table>"); |
sb.append("</table>"); |
57 |
|
sb.append("Rowcount: ").append(count); |
58 |
} catch (Exception e) { |
} catch (Exception e) { |
59 |
throw new ServletException(e); |
throw new ServletException(e); |
60 |
} finally { |
} finally { |
81 |
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { |
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { |
82 |
String dump = req.getParameter("dump"); |
String dump = req.getParameter("dump"); |
83 |
|
|
84 |
String res = "invalid dump parameter"; |
String res = null; |
85 |
|
|
86 |
if (dump.equals("all")) { |
if (dump != null) { |
87 |
res = dumpResultset("SELECT * FROM trainstations"); |
if (dump.equals("all")) { |
88 |
} else if (dump.equals("coords")) { |
res = dumpResultset("SELECT * FROM trainstations ORDER BY id"); |
89 |
res = dumpResultset("SELECT * FROM trainstations WHERE latitude IS NULL OR longitude IS NULL"); |
} else if (dump.equals("coords")) { |
90 |
|
res = dumpResultset("SELECT * FROM trainstations WHERE latitude IS NULL OR longitude IS NULL ORDER BY id"); |
91 |
|
} else if (dump.equals("duplicate")) { |
92 |
|
res = dumpResultset("SELECT name,count(*) FROM trainstations GROUP BY name HAVING count(*) > 1"); |
93 |
|
} else if (dump.equals("allfull")) { |
94 |
|
res = dumpResultset("select *, " + |
95 |
|
"'<a href=\"http://maps.google.com/?q=' ||latitude || ',' || longitude || '\">Maps</a>' AS maps, " + |
96 |
|
"'<a href=\"http://www.bane.dk/visStation.asp?ArtikelID=4275&W=FJRN&S=' || stationcode_fjrn || '\">Bane.dk Fjern</a>' as banedk1, " + |
97 |
|
"'<a href=\"http://www.bane.dk/visStation.asp?ArtikelID=4275&W=S2&S=' || stationcode_stog || '\">Bane.dk stog</a>' as banedk2 " + |
98 |
|
"FROM trainstations ORDER BY id"); |
99 |
|
} else if (dump.equals("disabled")) { |
100 |
|
res = dumpResultset("SELECT * FROM trainstations WHERE enabled = false ORDER BY id"); |
101 |
|
} else if (dump.equals("noaddress")) { |
102 |
|
res = dumpResultset("SELECT * FROM trainstations WHERE address IS NULL or address = '' "); |
103 |
|
} |
104 |
|
} |
105 |
|
if (res == null) { |
106 |
|
res = "<a href=DumpResultSet?dump=all>All</a><br><a href=DumpResultSet?dump=allfull>All with links</a><br><a href=DumpResultSet?dump=coords>Missing coords</a><br><a href=DumpResultSet?dump=duplicate>Duplicate stations</a><br><a href=DumpResultSet?dump=disabled>Disabled stations</a><br><a href=DumpResultSet?dump=noaddress>No address</a>"; |
107 |
} |
} |
108 |
|
|
109 |
resp.setContentType("text/html"); |
resp.setContentType("text/html"); |
110 |
resp.getWriter().println(res); |
resp.getWriter().println(res); |
111 |
} |
} |