Skip to content

Instantly share code, notes, and snippets.

@spariev
Created February 12, 2010 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spariev/302538 to your computer and use it in GitHub Desktop.
Save spariev/302538 to your computer and use it in GitHub Desktop.
;; make sure you have c3p0 jar in classpath
(def *c3p0-datasource*
(let [db-config (org.ho.yaml.Yaml/load (java.io.File. "../../config/database.yml"))
env-config (get db-config rails-env) ]
(doto (com.mchange.v2.c3p0.ComboPooledDataSource.)
(.setDriverClass "com.mysql.jdbc.Driver")
(.setJdbcUrl (str "jdbc:mysql://" (get env-config "host") "/" (get env-config "database")))
(.setConnectionTesterClassName "com.mysql.jdbc.integration.c3p0.MysqlConnectionTester")
(.setIdleConnectionTestPeriod 120)
(.setUser (get env-config "username"))
(.setPassword (get env-config "username")))))
; and then ...
(with-connection {:datasource *c3p0-datasource*}
...)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment