Thanks.

I have used C3P0 for now... I will look at tomcat7 pool though

Josh


On Fri, Sep 13, 2013 at 3:19 PM, gixxi <
christian.meichs...@informatik.tu-chemnitz.de> wrote:

> Hi Josh,
>
> I would opt for using Tomcat 7 Pool API -
> http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html
>
> The following code wraps the pool api and provides reading a config file
>
> (ns foo
>   (:require [clojure.java.io :as io])
>   (:import [java.io PushbackReader])
>   (:gen-class))
>
> (defn conf [file]
>   "Reads a config file containing the connection params (url, driver)"
>   (binding [*read-eval* false]
>     (with-open [r (io/reader file)]
>       (read (PushbackReader. r)))))
>
> (defn datasource [file]
>   "creates a pooled data source"
>   (let
>     [config (conf file) ds (new org.apache.tomcat.jdbc.pool.DataSource) pp
> (new org.apache.tomcat.jdbc.pool.PoolProperties)]
>     (do
>       (.setDriverClassName pp (:classname config))
>       (.setUrl pp (:subname config))
>       (.setUsername pp (:user config))
>       (.setPassword pp (:password config))
>       (.setTestOnBorrow pp true)
>       (.setValidationQuery pp "SELECT 1")
>       (.setMaxActive pp 5)
>       (.setInitialSize pp 1)
>       (.setMaxWait pp 10000)
>       (.setPoolProperties ds pp)
>       (identity ds))))
>
> create a file dbconnection.ini with you jdbc connection params as per the
> following example (uses derby in-memory db)
>
> {
> :classname "org.apache.derby.jdbc.EmbeddedDriver"
> :subprotocol "memory"
> :subname "jdbc:derby:memory:myDB;create=true"
> :user ""
> :password ""
> }
>
> now you can load the config and create a pooled connection as wished
>
> (def ds (datasource (clojure.java.io/as-file "db.properties")))
>
> you can obtain a connection using
>
> {:datasource ds}
>
>
> Cheers
> Christian
>
> Am Freitag, 13. September 2013 12:22:47 UTC+2 schrieb Josh Kamau:
>
>> Hello there ;
>>
>> I am in desparate need of a clojure.jdbc with a connection pool example.
>>
>> I have googled and the link to github example is broken.
>>
>> Please help.
>>
>> Thanks.
>> Josh
>>
>  --
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to