Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with storing Pic in Blob Field

 
Jaled Ahmed
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic