| Author |
saving image to database
|
Shashank Anand
Greenhorn
Joined: Oct 30, 2008
Posts: 26
|
|
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
Joined: Aug 01, 2008
Posts: 66
|
|
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
Joined: Jan 10, 2002
Posts: 56224
|
|
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.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
 |
|
|
subject: saving image to database
|
|
|