Hy guys,
I 've a problem with my java application.
I use hibernate to interact with a derby database.
I stored a image into blob field (and no problem).
When I try to get blob to array of byte I've this exception:
java.sql.SQLException: You cannot invoke other java.sql.Clob/java.sql.Blob methods after calling the free() method or after the Blob/Clob's transaction has been committed or rolled back.
To get blob I did
Blob cThumnb = ((Allegato) cAllegati.get(i)).getThumb();
byte[] cPrev = toByteArray(cThumnb);
where
private byte[] toByteArray(Blob fromBlob) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
return toByteArrayImpl(fromBlob, baos);
}
catch (SQLException e)
{
throw new RuntimeException(e);
}
catch (IOException e)
{
throw new RuntimeException(e);
}
finally
{
if (baos != null)
{
try
{
baos.close();
}
catch (IOException ex)
{
}
}
}
}
private byte[] toByteArrayImpl(Blob fromBlob, ByteArrayOutputStream baos) throws SQLException, IOException
{
byte[] buf = new byte[4000];
InputStream is = fromBlob.getBinaryStream();
try
{
for (;;)
{
int dataSize = is.read(buf);
if (dataSize == -1) break;
baos.write(buf, 0, dataSize);
}
}
catch(IOException ex)
{
throw ex;
}
finally
{
if (is != null)
{
try
{
is.close();
}
catch (IOException ex)
{
}
}
}
return buf;// baos.toByteArray();
}
Could you help me?
I set also autocommit to false,
Thanks,
Regards