Fork me on GitHub
#sql
<
2020-05-04
>
mbjarland14:05:15

I have a question which I’m assuming is trivial. Failed to find a reasonable answer so here we go: I have the following code using next.jdbc to connect to an oracle db:

(def url "jdbc:oracle:thin:@<someip>:<somepord>:<somesid>")
(let [ds   (jdbc/get-datasource {:jdbcUrl url :user "user" :password "pass"})]
  (with-open [c (jdbc/get-connection ds)]
    (println "result:" (jdbc/execute! c ["select 1 from dual"]))))
but when I execute this I get the following exception:
clojure.lang.ExceptionInfo: Method close on class oracle.jdbc.driver.T4CConnection not allowed!
not allowed to close the connection? eh…I have not seen this from other languages using the same jdbc url so I’m thinking I have some misconception about how next.jdbc works. Any help much appreciated

mbjarland15:05:06

If I skip with-open or send in the db spec {:jdbcUrl .. :user .. :password ..} directly to jdbc/execute! then no exception, but that leaves me wondering if I’m missing cleanup of resources and leaving connections hanging etc

dharrigan15:05:31

would you not consider using a connection pool library like hikaricp?

dharrigan15:05:05

it works fantastically well with next jdbc

mbjarland17:05:31

I could, but would prefer not to as I'm troubleshooting a production stack and trying to not introduce extra pieces in the puzzle

emccue17:05:57

I think that it should be fine

emccue17:05:13

It just stands up the connection from scratch

seancorfield17:05:55

That's a weird one. It clearly has a .close method, but that is implemented to throw an exception?

seancorfield17:05:11

@mbjarland Your usage looks correct at first glance but I haven't see folks using :jdbcUrl + :user/`:password` (it should work) and I don't test the library locally with Oracle (because, logistics!). Oracle definitely does a lot of very peculiar things tho'...

mbjarland18:05:37

Agreed, oracle is a strange beast

mbjarland18:05:37

And the URL + creds spec works and returns data, it just barfs when trying to close the connection after

4
mbjarland18:05:25

And yes, setting up oracle is total voodoo

mbjarland19:05:33

wow tried to read the decompiled code for T4CConnection and PhysicalConnection which it extends, that is a pretty convoluted process for just closing a connection

seancorfield19:05:02

If you can figure out why it doesn't work(!) and what the recommended approach for dealing with connection is, once you're done with them (I assume you're supposed to call something to mark the connection "done with"?), feel free to open an issue on the next.jdbc repo with suggestions for the Oracle section of the Tips &amp; Trick page.