Hi!
I've written the following Servlet to read an Image from a Mysql Database
and send it to the browser.
public class ImageServlet extends HttpServlet {
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException {
try {
InitialContext jndiContext = new InitialContext();
DataSource ds = (DataSource)jndiContext.lookup("java:/mySQLDS") ;
Connection conn = ds.getConnection() ;
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT image from docs where idx=" +
request.getParameter("idx"));
if (rs.next()) {
response.setContentType("image/gif");
PrintWriter out = response.getWriter();
out.println(rs.getString("file" + request.getParameter("idximg")));
response.flushBuffer();
}
rs.close();
stmt.close();
conn.close();
ds = null ;
} catch(Exception e){
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Error: "+e);
}
}
}
It works fine, but I've seen that it leaves mysql instances opened in my
server... Any idea ???
Cheers,
Papo
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://archives.java.sun.com/jsp-interest.html
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.jsp
http://www.jguru.com/faq/index.jsp
http://www.jspinsider.com