Fork me on GitHub
#sql
<
2021-01-15
>
Ronny Li14:01:44

Hi everyone, I'm using the following https://www.reddit.com/r/Clojure/comments/dyaqh6/connecting_to_snowflake_db_with_nextjdbc/f88k70a for connecting to Snowflake with next.jdbc. My question is: Is there a better way to create and close the connection per query? The reddit thread appears to only create the connection.

seancorfield17:01:06

That is super-complicated and absolutely not needed:

(def db-spec {:dbtype "snowflake" :classname "net.snowflake.client.jdbc.SnowflakeDriver" :user "..." :password "..." :host (str account-name ".")})
(def ds (jdbc/get-datasource db-spec))
(jdbc/execute! ds ["some sql here"])
^ that ought to work @ronny463

Ronny Li17:01:58

And just to check, is it okay for me to repeatedly use the same ds to execute queries or should I be creating a new one each time?

seancorfield17:01:12

Per the next.jdbc docs, you should make a datasource (which could be a plain datasource, one built from a db-spec via jdbc/get-datasource, or a connection pooled datasource) and then use the datasource everywhere.

seancorfield17:01:51

next.jdbc gets a Connection from the DataSource as needed and closes it out after use.

Ronny Li18:01:35

got it, thank you!

Ronny Li20:01:28

Hi Sean, just confirming that this worked perfectly. Thanks again!

seancorfield17:01:36

LMK if the above does work and then I can go respond to that thread...

Ronny Li17:01:53

Thank you @seancorfield! Your approach looks much simpler :) Unfortunately that thread is 1 year old so I think it's locked to future replies. It's also unfortunate that it's literally the first result when googling "next.jdbc Snowflake" 😛

seancorfield17:01:22

grumbles about Reddit not being a very good place to ask technical questions like that

😄 6