1 |
package com.grundfos.gmatou.dataupload;
|
2 |
|
3 |
import java.io.IOException;
|
4 |
import java.sql.Connection;
|
5 |
|
6 |
import javax.servlet.ServletException;
|
7 |
import javax.servlet.http.HttpServlet;
|
8 |
import javax.servlet.http.HttpServletRequest;
|
9 |
import javax.servlet.http.HttpServletResponse;
|
10 |
import java.sql.*;
|
11 |
|
12 |
|
13 |
public class ViewFile extends HttpServlet {
|
14 |
private static final long serialVersionUID = 1L;
|
15 |
|
16 |
|
17 |
public ViewFile() {
|
18 |
super();
|
19 |
}
|
20 |
|
21 |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
22 |
String strId = request.getParameter("id");
|
23 |
|
24 |
int id = Integer.parseInt(strId);
|
25 |
|
26 |
try
|
27 |
{
|
28 |
Connection conn = DBConnection.getDbConnection();
|
29 |
PreparedStatement stmt = conn.prepareStatement("SELECT data FROM dataentries WHERE ID = ?");
|
30 |
stmt.setInt(1, id);
|
31 |
ResultSet rs = stmt.executeQuery();
|
32 |
String data = " -- no data found with id=" + id;
|
33 |
while (rs.next())
|
34 |
data = rs.getString(1);
|
35 |
|
36 |
rs.close();
|
37 |
stmt.close();
|
38 |
conn.close();
|
39 |
|
40 |
response.setContentType("text/plain");
|
41 |
response.getWriter().print(data);
|
42 |
|
43 |
|
44 |
} catch (Exception e) {
|
45 |
throw new ServletException(e);
|
46 |
}
|
47 |
}
|
48 |
|
49 |
}
|