This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Dear Ranchers, I'm doing a HR System in JSP and MySQL. In some point i want to insert the employee photograph in to the database and also want to retrieve it back and display it in the jsp page.
I tried looking into the old POSTs and also in google search. I failed to get a solution for this. I will be thankful, if you could send me a sample code for inserting image into the database and also to retrieve it. I will be very thankful..
When I retrieve the image, I would like to give it a standard height and width, so that it can fit in a table data to make the HR System good looking..
How can I put the height and width in this code..[/QB]
The ImageInfo class can determine width and height of a number of image formats.
Joined: Dec 28, 2005
Dear Ranchers, I've tried converting the code for inserting image into the database in JSP and tried running it as localhost. It is working fine there. But when i went to another computer and used tried to access the same page, it is giving me error. The code is as follows
When an image has not been loaded yet it returns -1 for both width and height. This normally does not happen with ImageIcons, so probably the file is not valid. Possibly the file is incorrect, you'll probably have to convert it to something the remote file system understands.
Originally posted by Aravind Prasad: Ranchers.. No reply for my doubt.. expecting and waiting for a solution!!
Maybe if you worked on it on your own rather than expecting the code to be given to you you'd move faster towards your goal, all your posts seem to be asking for ready made solutions.
Thanks for the reply. Can you please find for me a solution. I too know the same actully.
Rob Prime already hinted at what the problem is and judging from your reply you already know what the problem is right? When you're running it on localhost, the server and the client from where you're uploading your image are the same machine so when the server looks for "c:\imageName.jpg" it finds it.
But when you access the app from a remote machine, "c:\remoteImageName.jpg" doesn't exist on the server, it's on the client. And the server doesn't have access to the client's filesystem. So it fails to locate and insert the image into the DB.
So, now that you know the problem, what could be a solution? You need to get the image onto the server's file system. You could look into uploading the image onto the server rather than simply using the filename to access the file; that would take care of this problem. [ September 24, 2007: Message edited by: Tarun Yadav ]
Originally posted by Jeanne Boyarsky: Annahita, Is herbariumNo a number or a string? The SQL statement implies it is a string, but it sounds like a number. If it is a number the quotes around it would cause an error in your SQL statement.
Also, is there any reason you aren't using a "?" for the number as well as the BLOB?
herbariumNo is a string. Anyway my problem is solved with a friend's help:
I should have written: result = st.executeUpdate();