File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

saving image to database

 
Shashank Anand
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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

//b.jsp
<%
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()));
ps.executeUpdate();
%>
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.



Regards,
Shashank


 
Mark Williams
Ranch Hand
Posts: 66
  • 0
  • 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?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64205
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • 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.

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic