File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Problem with storing Pic in Blob Field Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Problem with storing Pic in Blob Field" Watch "Problem with storing Pic in Blob Field" New topic

Problem with storing Pic in Blob Field

Jaled Ahmed

Joined: Feb 21, 2004
Posts: 1
I'm getting the following error with Tomcat 4.1.30:- D:\186209.jpg (No such file or directory)

Here is my code:-


File file = new File(request.getParameter("Imagen"));
FileInputStream fis = new FileInputStream(file);

Pstatement = connection.prepareStatement("INSERT INTO viajes (Agencia,Tipo,Titulo,OContenente,OPais,OCiudad,DContenente,DPais,DCiudad,PSalida,USalida,Imagen) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)");

Pstatement.setString(1, AgenciaNombre);
Pstatement.setString(2, request.getParameter("Tipo"));


} catch (Exception e)



The Problem is that code working correctlly with my local host Tomcat and MySQL but it didn't work within my web site that use the same versions of TomCat and MySQL

Jaled Ahmed
Charles Lyons
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
It looks like you're trying to open a stream to the file D:\186209.jpg - but does this exist on the server as well as on your localhost. More to the point, is your server actually a Windows box - if it's *nix, then there is no "D:\" path anyway?!

And by the way, the above code would be better located in a servlet, not a JSP, due to the amount of processing.

In addition, you extract the local file name from a request parameter - do you really want to expose the structure of your file server to the world? You would be better using some servlet logic to map a public external name to the actual local file name - this also has the benefit of aliasing the file name in case of future change (so you can change the local name, but keep the public one the same; makes the application more robust).
[ March 16, 2006: Message edited by: Charles Lyons ]

Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
I agree. Here's the link:
subject: Problem with storing Pic in Blob Field
jQuery in Action, 3rd edition