Search code examples
databaseclojure

Clojure how to insert a blob in database?


How to insert a blob in database using the clojure.contrib.sql?

I've tried the following reading from a file but I'm getting this exception:

SQLException: Message: Invalid column type SQLState: 99999 Error Code: 17004 java.lang.Exception: transaction rolled back: Invalid column type (repl-1:125)

(clojure.contrib.sql/with-connection
   db
   (clojure.contrib.sql/transaction
    (clojure.contrib.sql/insert-values :test_blob [:blob_id :a_blob] [3   (FileInputStream. "c:/somefile.xls")]) ))

Thanks.


Solution

  • I was able to solve this by converting the FileInputStream into a ByteArray.

    (clojure.contrib.sql/with-connection 
       db 
       (clojure.contrib.sql/transaction 
        (clojure.contrib.sql/insert-values :test_blob [:blob_id :a_blob] [3   (to-byte-array(FileInputStream. "c:/somefile.xls"))]) ))