如何从MySQL读取LONGBLOB

如何从MySQL读取LONGBLOB

本文介绍了如何从MySQL读取LONGBLOB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个pdf作为LONGBLOB存储在数据库中。



我需要使用Groovy脚本检索二进制输出流。



我试过这个:

  rowTest = sql.firstRow(select data from mytable id = 666); 
file = rowTest [0];
myLongBlob =(oracle.sql.BLOB)文件;但是,我得到了一个强制异常:


  javax.script.ScriptException:javax.script.ScriptException:org.codehaus.groovy.runtime.typehandling.GroovyCastException:无法通过类'[B']投射对象'[B @ 48eb2326'到类'oracle.sql.BLOB'

然后我意识到我试图把一个LONGBLOB BLOB这可能是为什么这个错误发生的原因?



无论如何,还有另一种方式从LONGBLOB读取我的PDF?



感谢。



编辑:错误不是由于将LONGBLOB转换为BLOB,我尝试使用BLOB并发生相同的错误。

编辑:我试图遵循本教程:

解决方案

一个对象'[B @ 48eb2326'是指字节数组;在 rowTest [0] 的对象是 byte [] ,而不是 code>。所以最简单的事情可能是 byte [] myLongBlob =(byte [])文件(这可能更方便你使用,反正!)。 >

I have a pdf stored in a database as a LONGBLOB.

I need to retrieve it binary output stream with a Groovy script.

I've tried this :

rowTest = sql.firstRow("select data from mytable id = 666");
file = rowTest[0];
myLongBlob = (oracle.sql.BLOB)file;

However, I get a cast exception :

javax.script.ScriptException: javax.script.ScriptException: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[B@48eb2326' with class '[B' to class 'oracle.sql.BLOB'

Then I realized I was trying to cast a LONGBLOB to a BLOB which is probably the reason why this error happens ?

Anyway, is there another way to read my PDF from a LONGBLOB ?

Thanks.

Edit : The error is not due to casting a LONGBLOB to BLOB, I tried with a BLOB and same error happens.

Edit : I'm trying to follow this tutorial : http://groovy.codehaus.org/Reading+from+a+Blob

解决方案

An object '[B@48eb2326' refers to a byte array; the object at rowTest[0] is a byte[], not a Blob. So the easiest thing would probably be byte[] myLongBlob = (byte[]) file (which is probably more convenient for you to work with, anyway!).

这篇关于如何从MySQL读取LONGBLOB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 07:18