Fork me on GitHub
Ronny Li14:01:44

Hi everyone, I'm using the following 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.


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?


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.


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!


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" 😛


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

😄 6