Skip to content

Commit

Permalink
use java intop with jdbc to get db driver to connect
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWheeler committed Oct 24, 2016
1 parent 31c6822 commit 3af3688
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/airlift/core.clj
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
(ns airlift.core
(:gen-class))
(:gen-class)
(:require [airlift.db :as db]))

(defn export-tables
[]
(let [config (read-string (slurp "config.edn"))]
(println config)))

(defn -main [& args]
(export-tables))
(println (db/query "SELECT * Table")))
20 changes: 19 additions & 1 deletion src/airlift/db.clj
Original file line number Diff line number Diff line change
@@ -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))))

0 comments on commit 3af3688

Please sign in to comment.