I need to read bytes from this Blob. I’m trying the following but I’m getting this exception:
oracle.sql.BLOB cannot be cast to [B
(defn select-test2[]
(clojure.contrib.sql/with-connection db
(with-query-results res ["SELECT my_blob from some_table"] (doall res))))
(defn obj [byte-buffer]
(if-not (nil? byte-buffer)
(with-open [object-in (ObjectInputStream.
(ByteArrayInputStream. byte-buffer))]
(.readObject object-in))))
(obj (:my_blob (first (select-test2))))
[Bis the “class” of a byte array:So there’s a place in your code that is expecting a byte array, but it’s being given an
oracle.sql.Blobinstance. My bet is that:my_blobis giving you aBlob; when you passbyte-buffer(which is theBlob) to theByteArrayInputStreamconstructor, you get the exception.Look up the javadocs for
oracle.sql.Blobto see how to extract a byte array or input stream from it.