Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: Clob to byte[] [closed]

How can I read a java.sql.Clob into a byte[]?

like image 931
Victor Avatar asked Dec 21 '22 17:12

Victor


2 Answers

with commons-io

byte[] data = IOUtils.toByteArray(clob.getAsciiStream());
like image 133
A.Alexander Avatar answered Jan 02 '23 02:01

A.Alexander


int length = clob.getLength();         
 byte[] array = new byte[length];       
 InputStream in = clob.getAsciiStream();       
 int offset = 0;        
 int n;        
 do      
    n = in.read(array, offset, length - offset);        
 while (n != -1);

Try the above snippet of code for reading a clob into Byte array.

like image 31
Deepak Avatar answered Jan 02 '23 01:01

Deepak