aspose file tools*
The moose likes JDBC and the fly likes Storing in BLOC column. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Storing in BLOC column." Watch "Storing in BLOC column." New topic
Author

Storing in BLOC column.

Alex Marks
Ranch Hand

Joined: Sep 12, 2005
Posts: 31
Hi Everyone,
I am using a HTML form to upload a file(picture/image), at the server-side, I'd like to store it in BLOB column. However,I dont know how to store the file in such column. Anyone,please help me to solve this problem.
Thank you in advance and looking for your replies ASAP.


Before I come here, I am confused about Servlet/JSP. Ater I come here, I am more confused about it, but in systematically.
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1121

Alex,
Different databases have different ways of dealing with BLOB columns, so I don't think anyone will be able to answer your question until you tell us which database you are using.

Good Luck,
Avi.
Alex Marks
Ranch Hand

Joined: Sep 12, 2005
Posts: 31
I am using Oracle database, I have seen some solutions but I am not so sure how to do it ! Would you please help me? Thank you in advance!
Shivakumar Mallikarjun
Greenhorn

Joined: Jul 08, 2005
Posts: 4
You can insert file data into BLOB column in Oracle DB by first reading the file as ByteStream & later inserting that into BLOB column.
One more thing you can't insert data into BLOB/CLOB column by Stored Procedures/Functions, you have to embed the SQL in your Java application.
Hope this serves your purpose.
Alex Marks
Ranch Hand

Joined: Sep 12, 2005
Posts: 31
Can you give me the piece of code how to convert the file to the stream of byte ? Thank you in advance
Alex Marks
Ranch Hand

Joined: Sep 12, 2005
Posts: 31
Shivakumar,
As you said, first i need to read the file as ByteStream, do i need to store the file temporary first? then i read or i can read directly?
Shivakumar Mallikarjun
Greenhorn

Joined: Jul 08, 2005
Posts: 4
Here is the code to read word & pdf files in byte format, presume that pdfdata is the form field name which contains file data

if(pdfdata != null){
byte byteData[] = pdfdata;

}
After this you can use pdfdata in INSERT SQL query statement to insert the data into table.
Hope this helps you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Storing in BLOC column.
 
Similar Threads
How do we store objects in database table?
store large image into oracle blob column
how to store value from servlet to java script variable
XML Processing
Upload file or pdf in database with its extension in separate column