Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle Database BLOB to InputStream in Java?

I made a Java function that takes an InputStream as an input. I have a oracle.sql.BLOB instance to pass to that function. How can I convert it to a InputStream?

Do I need to re-write my function using a BLOB parameter, instead?

like image 350
Data-Base Avatar asked Dec 16 '22 07:12

Data-Base


2 Answers

You haven't really said how you're fetching data from the database, but you can use ResultSet.getBinaryStream() to get an InputStream, or call getBlob() to get a Blob, and then getBinaryStream() on the Blob to get a stream.

like image 50
Jon Skeet Avatar answered Dec 27 '22 23:12

Jon Skeet


Declare your Java parameter of type oracle.sql.BLOB as per the "Mapping Datatypes" documentation. Then, you call getBinaryStream() on that BLOB object to obtain your InputStream.

like image 30
Adam Paynter Avatar answered Dec 27 '22 23:12

Adam Paynter