This was going to be a question but I solved it before I finished the
post :)
Figured I might post the solution then, hopefully it will help someone
else.
(import '(java.sql Connection DriverManager ResultSet SQLException
Statement ResultSetMetaData))
(import '(org.postgresql Driver))
(defn connect-postgresql []
(let [name "jdbc:postgresql://localhost:5432/flonk"]
(DriverManager/getConnection name "postgres" "qwerasdf")))
(defn connect-postgresql2 []
(let [name "jdbc:postgresql://localhost/test"]
(DriverManager/getConnection name "postgres" "qwerasdf")))
(connect-postgresql)
that establishes a connection(both examples work).
How would I do it with contrib.sql?
First create a db with with postgresql(pgadmin3 makes this very easy).
then connect and manipulate with the following, given that you named
the database flonk.
(ns progs.netflix.db
(:require (clojure.contrib [sql :as sql]))
(:require (clojure.contrib.sql [internal :as internal])))
(load-file "C:/clojure/user.clj")
(def db {:classname "org.postgresql.Driver"
:subprotocol "postgresql"
:subname "//localhost/flonk"
:user "postgres"
:password "1234qwer"
})
(defn drop-deleta []
(try
(sql/drop-table :deleta)
(catch Exception e)))
(defn create-and-drop-previous []
(sql/with-connection db
(sql/transaction
(drop-deleta))))
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---