Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Storing in BLOC column.

 
Alex Marks
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic