Fork me on GitHub
#sql
<
2022-12-09
>
dumrat11:12:29

next.jdbc How do I read a blob? I get connection closed error when I try to do .getBinaryStream . Do I have to do inside a transaction? I'm not using pooling

dumrat12:12:01

Inside a transaction works

hiredman17:12:25

you have to do it while the connection is open, doing inside a transaction just happens to do that

hiredman17:12:16

if you are just passing a map of connection parameters into plan or select or whatever, the connection is opened inside those and closed by the time they return

👍 1
seancorfield17:12:28

(the CLOB reading examples there use a stream but open and close it "atomically" to avoid the connection closed issue)

dumrat17:12:31

@U04V70XH6 I managed to get it working in the end. Got bitten by two things: 1. Connection closed error because I was using a connection param map

dumrat17:12:18

2. Trying to extend rs/ReadableColumn to java.sql.Blob failed and then I read the docs 😄

dumrat17:12:27

A bit pain to work with Blobs it seems because I have to think about the connection

seancorfield18:12:30

If you use .getBytes you shouldn't have to. If you use .getBinaryStream I would expect you'd need to use with-open and read the entire BLOB inside that.

👍 1