diff --git a/project.clj b/project.clj index bb25e26..b08ac37 100644 --- a/project.clj +++ b/project.clj @@ -7,7 +7,7 @@ [org.clojure/data.csv "0.1.3"] [org.clojure/core.async "0.2.395"] [org.clojure/java.jdbc "0.6.2-alpha3"] - [net.sourceforge.jtds/jtds "1.2.4"] + [com.microsoft/sqljdbc4 "3.0"] [clj-ssh "0.5.14"] ] :main airlift.core diff --git a/src/airlift/core.clj b/src/airlift/core.clj index d3af716..159d891 100644 --- a/src/airlift/core.clj +++ b/src/airlift/core.clj @@ -1,5 +1,6 @@ (ns airlift.core - (:gen-class)) + (:gen-class) + (:require [airlift.db :as db])) (defn export-tables [] @@ -7,4 +8,4 @@ (println config))) (defn -main [& args] - (export-tables)) + (println (db/query "SELECT * Table"))) diff --git a/src/airlift/db.clj b/src/airlift/db.clj index 5beec13..3aec6f2 100644 --- a/src/airlift/db.clj +++ b/src/airlift/db.clj @@ -1,2 +1,20 @@ (ns airlift.db - (:require [clojure.java.jdbc :as sql])) + (:require [clojure.java.jdbc :as sql]) + (:import [com.microsoft.sqlserver.jdbc.SQLServerDriver])) + +(def db (com.microsoft.sqlserver.jdbc.SQLServerDriver.)) + +(defn config [username password] + "returns correct java.util.Properties instance" + (let [c (java.util.Properties.)] + (.setProperty c "user" username) + (.setProperty c "password" password) + c)) + +(defn connect [db host port dbname config] + (.connect db (str "jdbc:sqlserver://" host ":" port ";databaseName=" dbname) config)) + +(defn query [query] + (let [connection (connect db "127.0.0.1" "1433" "db_name" (config "username" "password"))] + (.. connection (createStatement) (executeQuery query)))) +