问题
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