Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

saving image to database

Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have following code to save an image into a database (msql - datatype blob).

File f = new File("c:/myfiles/pictures/bird.jpg");
FileInputStream fis = new FileInputStream(f);
//connection code here...
PreparedStatement ps = con.prepareStatement("INSERT INTO mytable (image) VALUES(?)");
ps.setBinaryStream(1, (InputStream) fis, (int) (f.length()));
It works and I can retrieve the image as well.
I have another page a.jsp linked to b.jsp with <form> tag.
There is a text field (name=image) in a.jsp. If I type c:/myfiles/pictures/bird.jpg in the text field and try to retrieve it in b.jsp,
the code doesn't work. Anyone please tell me where it went wrong? The code I am using is:
String img=request.getParameter("image");
File f = new File("img");
//same code as above.


Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

That is your problem right there... You want to pass the identifier img (without quotes) to the constructor.

BTW, this isn't Shashank that took CS classes at Loyola in New Orleans with me is it?
Posts: 67403
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please take the time to choose the correct forum for your posts. This forum is for questions on JSP.

For more information, please read this.

This post has been moved to a more appropriate forum.

Bring out your dead! Or a tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic