Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with storing Pic in Blob Field  RSS feed

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
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
Boost this thread!