aspose file tools*
The moose likes JDBC and the fly likes Inserting images in to the database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Inserting images in to the database" Watch "Inserting images in to the database" New topic
Author

Inserting images in to the database

Aravind Prasad
Ranch Hand

Joined: Dec 28, 2005
Posts: 265
Dear Ranchers,
I'm using Java Swing with MySQL as the database for developing a Human Resource application. In a particular point i want to insert the photograph of the employees in to the system. From my friends i heard, we can use BLOG for inserting images into the system.

Can any one please send me the sample code for inserting the image into the database and retrieving the image from the database.

Please help me ranchers

Thanks in advance

regards
Aravind Prasad
Dave Wingate
Ranch Hand

Joined: Mar 26, 2002
Posts: 262
I think your buddy probably said "blob," not "blog." A blob is a database column type that represents an arbitrary sequence of bits which the developer can interprit as s/he pleases ... in your case, the blob will be interpreted as an image.

Here's a good article that describes using java to read/write image blobs to a mysql database. article


Fun programming etcetera!
Aravind Prasad
Ranch Hand

Joined: Dec 28, 2005
Posts: 265
Dear Ranchers,
I've searched in the internet for inserting image into BLOB and i got some sample codings like this. I've created 2 jsp pages.
1. index.jsp

2.upload.jsp

When i run the following page, i'm getting error here. The error is here


what may be the error. Please help me to solve this..

Thanks in advance

regards
Aravind Prasad
Dave Wingate
Ranch Hand

Joined: Mar 26, 2002
Posts: 262
The class File is in the package java.io. You should add "java.io.*" to the imports for your jsp.
Tony Burleson
Greenhorn

Joined: Dec 31, 2006
Posts: 6
It seems that there isn't an page declaration to import java.io.*. You are using java.io.BufferedReader.

Hope this helps.
William Janssen
Ranch Hand

Joined: Jan 02, 2007
Posts: 39
Besides the declartion of import of the java.io.* package which causes the errors you show us there are some other hints for you in order to let the code work.
For a form to upload a file you should specify an enctype attribute on the form element with the value multipart/form-data.
Also for handling the uploaded data in the right way (now you only read the first byte of the stream) look at a package like FileUpload from apache commons (http://jakarta.apache.org/commons/fileupload/).
And please use a finaly block to close the connection.
 
jQuery in Action, 2nd edition
 
subject: Inserting images in to the database