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.
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 ".<http://snowflakecomputing.com|snowflakecomputing.com>")})
(def ds (jdbc/get-datasource db-spec))
(jdbc/execute! ds ["some sql here"])
^ that ought to work @ronny463LMK if the above does work and then I can go respond to that thread...
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" 😛
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.
grumbles about Reddit not being a very good place to ask technical questions like that
got it, thank you!
Hi Sean, just confirming that this worked perfectly. Thanks again!
Thanks @ronny463!