aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Problem with storing Pic in Blob Field" Watch "Problem with storing Pic in Blob Field" New topic
Author

Problem with storing Pic in Blob Field

Jaled Ahmed
Greenhorn

Joined: Feb 21, 2004
Posts: 1
Hello,
I'm getting the following error with Tomcat 4.1.30:-

java.io.FileNotFoundException: 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"));
Pstatement.setString(3,request.getParameter("Titulo"));
Pstatement.setString(4,request.getParameter("Ocon"));
Pstatement.setString(5,request.getParameter("Opais"));
Pstatement.setString(6,request.getParameter("Ociudad"));
Pstatement.setString(7,request.getParameter("Dcon"));
Pstatement.setString(8,request.getParameter("Dpais"));
Pstatement.setString(9,request.getParameter("Dciudad"));
Pstatement.setString(10,request.getParameter("PSalida"));
Pstatement.setString(11,request.getParameter("USalida"));
Pstatement.setBinaryStream(12,fis,(int)file.length());

Pstatement.executeUpdate();


} catch (Exception e)
{

out.println(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
Author
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 )
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem with storing Pic in Blob Field