File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes How to get Outputstream from oracle blob 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 "How to get Outputstream from oracle blob " Watch "How to get Outputstream from oracle blob " New topic
Author

How to get Outputstream from oracle blob

Faraz Ahmad
Greenhorn

Joined: Mar 11, 2008
Posts: 1
Hi,

i am using oracle10g and Weblogic 10(Java 5)

Follwing is the snippet of code :

ResultSet rSet;
.
.
.
.
.
Blob blob1 = rSet.getBlob(1);

oracle.sql.BLOB blob2 = (oracle.sql.BLOB)blob1;

OutputStream os = blob2.getBinaryOutputStream();


Here is the exception i m getting.

java.lang.ClassCastException: weblogic.jdbc.wrapper.Blob_oracle_sql_BLOB

at line typecasting blob1 to blob2.

Can anyone help me out?

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29220
    
135

Faraz,
Welcome to JavaRanch!

This code snippet is dangerous as it relies on a specific implementation



The ResultSet interface provides a method to get the binary stream directly. Why not just use that?


[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
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2476
    
    7

What Jeanne said. If you follow her approach, you 'll get your data.

About your error.
Blob blob1 can't be casted into an oracle.sql.BLOB.
The returned BLOB you got from rSet.getBlob(1) is not convertible to oracle.sql.BLOB.


OCUP UML fundamental and ITIL foundation
youtube channel
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get Outputstream from oracle blob
 
Similar Threads
write a bytearray to an oracle db
Servlet + Oracle9Ii help needed
Please help me complete steps to upload an image
Storing blob > 4kb in oracle db through jdbc
write a bytearray to an oracle db