Back
get-connection (clj)
(source)function
(get-connection spec)
(get-connection spec opts)
(get-connection spec user password)
(get-connection spec user password opts)
Given some sort of specification of a database, return a new `Connection`.
In general, this should be used via `with-open`:
```clojure
(with-open [con (get-connection spec opts)]
(run-some-ops con))
```
If you call `get-connection` on a `DataSource`, it just calls `.getConnection`
and applies the `:auto-commit` and/or `:read-only` options, if provided.
If you call `get-connection` on anything else, it will call `get-datasource`
first to try to get a `DataSource`, and then call `get-connection` on that.
If you want different per-connection username/password values, you can
either put `:user` and `:password` into the `opts` hash map or pass them
as positional arguments.