aspose file tools*
The moose likes JDBC and the fly likes How do I insert an image into a database from a servlet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How do I insert an image into a database from a servlet?" Watch "How do I insert an image into a database from a servlet?" New topic
Author

How do I insert an image into a database from a servlet?

Aditya Vasudeva
Ranch Hand

Joined: May 27, 2008
Posts: 76
I have a web page in which i have a browse button which selects an image on my local hard disk. I have a submit button which submits the file to the server.

How do I insert this image into a BLOB attribute in a table of my database.
The data type of the image specified in the database is type BLOB.

Please specify the code if possible.

Please help.
Thank You.
[ October 26, 2008: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

People here are happy to help you with your code, but are unlikely to write it for you. What have you got so far?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Aditya Vasudeva
Ranch Hand

Joined: May 27, 2008
Posts: 76
This is the form I am using to submit the request to the database.




Here is my servlet. It takes in the url of the image on my hard disk in the File fBlob. Is this code correct? It doesnt work when I click the submit button. It throws an SQLException giving the column name in which I am trying to insert the BLOB i.e. PHOTOGRAPH.



Please help me now...
Thank You
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31069
    
232

The SQL Exception would be due to an invalid SQL statement.


Here you specify two column values but only one column name. You'll need to add a second column name to synch things up.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I insert an image into a database from a servlet?