Skip to content

Instantly share code, notes, and snippets.

@robertlj
Forked from gdeer81/oracle-db-update.clj
Created July 11, 2018 16:57
Show Gist options
  • Save robertlj/fdbadc4a0bc8a8fde6463496edb95d2e to your computer and use it in GitHub Desktop.
Save robertlj/fdbadc4a0bc8a8fde6463496edb95d2e to your computer and use it in GitHub Desktop.
an example of updating an oracle database from clojure the server, user names, and passwords have been changed to protect the innocent
(ns db-test.core
(:require [clojure.java.jdbc :as j])
(use [korma.db])
(use [korma.core])
(:gen-class))
(defn setup-connection []
(def oracle-db {:classname "oracle.jdbc.odbc.OracleDriver"
:subprotocol "oracle"
:subname "thin:@//remotehost:1521/derpina1"
:user "user"
:password "pass" })
(j/get-connection oracle-db)
(default-connection oracle-db)
(defentity PGDV_REPAIR))
(def records (select PGDV_REPAIR (fields :PROD_ID :RETAIL :GOTO_RETAIL) (where {:REPAIR_ID [in [2 5]]})))
(defn alter-goto-repair []
(doseq [row records]
(update PGDV_REPAIR
(set-fields {:GOTO_RETAIL (+ (rand-int 100) (:RETAIL row))})
(where {:REPAIR_ID [in [2 5]]})
(where {:PROD_ID (:PROD_ID row)}))))
(defn -main
"This function is where all the functions in this namespace come together"
[& args]
(setup-connection)
(alter-goto-repair))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment