How to read a LONGBLOB from MySQL

怎甘沉沦 提交于 2019-12-11 03:46:01

问题


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


回答1:


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!).



来源:https://stackoverflow.com/questions/20164860/how-to-read-a-longblob-from-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!