-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use java intop with jdbc to get db driver to connect
- Loading branch information
1 parent
31c6822
commit 3af3688
Showing
3 changed files
with
23 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)))) | ||
|