Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bouzuya
Created January 8, 2013 14:36
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 bouzuya/4484208 to your computer and use it in GitHub Desktop.
Save bouzuya/4484208 to your computer and use it in GitHub Desktop.
(require '[clojure.java.jdbc :as sql])
(def db
"postgresql://postgres:postgres@localhost:5432/shouter")
(sql/with-connection db
(try (sql/drop-table :testing) (catch Exception _)))
(sql/with-connection db
(sql/create-table :testing [:data :text]))
(sql/with-connection db
(sql/insert-rows
:testing
["Hello, world!"]
["Hello, PostgreSQL!"]))
(sql/with-connection db
(sql/with-query-results results
["select * from testing"]
(into [] results)))
@bouzuya
Copy link
Author

bouzuya commented Jan 8, 2013

https://devcenter.heroku.com/articles/clojure-web-application#connecting-to-postgresql-with-clojurejavajdbc

Clojure から RDBMS を操作するため、上記 URL を写経 + 一部改変。 PostgreSQL を使った例。

@bouzuya
Copy link
Author

bouzuya commented Jan 8, 2013

Apache Derby 版は https://gist.github.com/4484275

project.clj[postgresql "9.1-901.jdbc4"] も忘れずに。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment