user3744303
user3744303

Reputation: 13

CLOB to binarystream conversion

How to convert Clob data to Binarystream ?

I can able to find it in 2 steps as of now, 1--> CLOB to String 2---> String to BinaryStream.

I am calling a SQL package which has 1 i/p and 2 o/p and assigning the CLOB output to some variable XYZ, sample is shown below...

Clob XYZ=null;
CallableStatement CalSmt = null;
InputStream ABC = null;
try
{
 CalSmt = conn.prepareCall("{call package(?,?,?)}");
 CalSmt.registerOutParameter(1,OracleTypes.CLOB);
 CalSmt.registerOutParameter(2,OracleTypes.INTEGER);
 CalSmt.setString(3,"315141");
 CalSmt.execute();
 XYZ = CalSmt.getClob(1);
 ABC= **XYZ.getBinaryStream();** <---- this is showing me a error as 'Method "getBinaryStream" not found'
}

Here XYZ is holding the CLOB data which needs to be converted to Binary Stream and Saved into ABC for further references. Kindly help me out by providing a single method for this plz. Thanks in Advance.

Upvotes: 1

Views: 946

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1499890

Yes, there's no getBinaryStream method on Clob, because it doesn't make sense for there to be one. A clob is character data, not binary data. It makes no more sense to ask a clob for a binary stream than it does to ask a blob for a character stream.

Your approach of converting to a string seems reasonable to me, to be honest, if you really need this conversion. It would be better if you could just avoid it though - if you're storing binary data, use a blob and InputStream everywhere. If you're storing character data, use a clob and Reader everywhere.

Upvotes: 2

Related Questions