0

I'm attempting to connect clojure to an odbc data source. The datasource is a SQL Server 2014 database, configured with a System DSN "someDatabase". The DB uses windows authentication. The ODBC source is configured properly, and I'm able to connect using the DriverManager in java. I get the following error when attempting to connect with clojure/java.jdbc:

SQLException [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified  sun.jdbc.odbc.JdbcOdbc.createSQLException (:-1)

core.clj

(ns deleteme.core)
(require '[clojure.java.jdbc :as j])
(def db-spec {:classname "sun.jdbc.odbc.JdbcOdbcDriver"
          :subprotocol "odbc"
          :subname "jdbc:odbc:someDatabase"})
(j/with-connection db-spec
      (j/with-query-results rs ["select top 10 * from someTable"] 
       (doseq [row rs] (println (:name row)))))

project.clj

(defproject deleteme "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.6.0"]
             [org.clojure/java.jdbc "0.1.1"]
])

Clearly I'm missing something.

os: Windows 7 32 bit

ZeroEric
  • 371
  • 1
  • 4
  • 7

1 Answers1

1

Seems like you're definitely finding the right driver.

Does this work from Clojure?

(Class/forName "sun.jdbc.odbc.JdbcOdbcDriver")
(def conn (java.sql.DriverManager/getConnection "jdbc:odbc:someDatabase"))
(def rs (.executeQuery (.createStatement conn) "select top 10 * from someTable"))

Trying to tell whether the issue is inside or outside java.jdbc.

Since this works, I would strongly suspect that something about the way that java.jdbc builds or sets the connection properties is resulting in something other than the above. I think in particular subname should probably just be "someDatabase". java.jdbc is building the jdbc:odbc part from the subprotocol for you.

Alex Miller
  • 69,183
  • 25
  • 122
  • 167