Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Read Blobs

 
Raj Puri
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an Oracle database with tables(BLOBS) populated with pdf or word files and I want to read the table and output it to screen so that user can view in browser. Any code snippet will help. Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65110
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to Servlets.
 
Raj Puri
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any one on this please?
 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should move your question to JDBC forum anyway here is an:
Blob b = rs.getBlob(1);
int len = (int)b.length();
byte [] _blob = b.getBytes(1, len);
Oracle can provide only limited number of bytes in this use, so you won't be able to read multi gig files. If it's your case, then let me know, and I will give you Oracle specific example working with huge files.
 
Raj Puri
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess only administrator can move this to JDBC. I have big files
typically 1 MB+. Can you post your code in this instance for our learning. Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65110
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless you are having trouble putting the data into the db (which I assume from your original post that you are not) then this is not a JDBC question. From your original question (and the repeat you posted in JSP) I assume that the problem you are having is with streaming the data to the browser?
[ May 20, 2005: Message edited by: Bear Bibeault ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you trying to process the files on the server and render them as HTML or do you just want to stream the files "en masse" down to the browser?
 
Raj Puri
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have files stored as word, pdf, xls in database. I do not have problem retriving them into a Blob variable from database. Only question is how to show them in browser. I will expect pdf should open in browser in acrobat, word in word and xls in excel. This is where I have problem. My approach to use in JSP did not work as I believe the setcontenttype failed and it shows like bunch of data. Any idea? I read from posting above I should do servlet but why - After all JSP==Servlet?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, streaming binary data from JSPs is ugly at best.
Here is an example. It doesn't use blobs. It uses files retrieved
with getResourceAsStream but, once you get the blob into an inputStream
everything else should be the same.
The key line (bold) is the content disposition header.
The "inline" keyword tells your browser to open the document as an embedded
PDF or Excel sheet.
The contentType header tells it what what the file is so it can pick the right application.

[ May 20, 2005: Message edited by: Ben Souther ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic