package com.grundfos.gmatou.dataupload; import java.io.IOException; import java.sql.Connection; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.sql.*; public class ViewFile extends HttpServlet { private static final long serialVersionUID = 1L; public ViewFile() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String strId = request.getParameter("id"); int id = Integer.parseInt(strId); try { Connection conn = DBConnection.getDbConnection(); PreparedStatement stmt = conn.prepareStatement("SELECT data FROM dataentries WHERE ID = ?"); stmt.setInt(1, id); ResultSet rs = stmt.executeQuery(); String data = " -- no data found with id=" + id; while (rs.next()) data = rs.getString(1); rs.close(); stmt.close(); conn.close(); response.setContentType("text/plain"); response.getWriter().print(data); } catch (Exception e) { throw new ServletException(e); } } }