Win a copy of Terraform in Action this week in the Cloud 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Inserting images in to the database

 
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Aravind Prasad
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 262
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The class File is in the package java.io. You should add "java.io.*" to the imports for your jsp.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems that there isn't an page declaration to import java.io.*. You are using java.io.BufferedReader.

Hope this helps.
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic