sql

All things SQL and JDBC...
mbjarland 2020-05-04T14:01:15.396900Z

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

mbjarland 2020-05-04T15:07:06.398300Z

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

dharrigan 2020-05-04T15:09:31.399100Z

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

dharrigan 2020-05-04T15:10:05.399900Z

it works fantastically well with next jdbc

mbjarland 2020-05-04T17:09:31.401600Z

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

emccue 2020-05-04T17:17:57.402Z

I think that it should be fine

emccue 2020-05-04T17:18:13.402600Z

It just stands up the connection from scratch

seancorfield 2020-05-04T17:23:55.403200Z

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

seancorfield 2020-05-04T17:37:11.406400Z

@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'...

mbjarland 2020-05-04T18:54:37.407Z

Agreed, oracle is a strange beast

mbjarland 2020-05-04T18:55:37.408600Z

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

1
mbjarland 2020-05-04T18:56:25.409500Z

And yes, setting up oracle is total voodoo

mbjarland 2020-05-04T19:03:33.410500Z

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

seancorfield 2020-05-04T19:06:02.412Z

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 & Trick page.

mbjarland 2020-05-04T19:35:39.412200Z

ok will do