Fork me on GitHub
#sql
<
2018-02-12
>
anler20:02:27

this finally worked:

(let [url  "jdbc:"
        stmt (-> (DriverManager/getConnection url)
                 (.createStatement)
                 (.executeQuery "select * from users"))]
    (while (.next stmt)
      (println (.getString stmt "name"))))
but I had to add an exclusion to clojure.java.jdbc:
[org.postgresql/postgresql "42.0.0.jre7"]
[org.clojure/java.jdbc "0.4.2" :exclusions [org.postgresql]]
@seancorfield I guess clojure.java.jdbc is using [org.postgresql/postgresql "9.4.1212.jre7"] and hasn't updated it for backwards compatibility?

seancorfield20:02:57

Are you really using 0.4.2 of java.jdbc??? That's ancient!

seancorfield20:02:15

And it shouldn't pull in any JDBC drivers so you should not need an exclusion.

seancorfield20:02:45

The current version is [org.clojure/java.jdbc "0.7.5"] @inbox

anler20:02:33

this is my first clojure project and now I see is a legacy one 😄

anler20:02:51

I'll see if I can update it and test again 🙂

seancorfield20:02:01

The java.jdbc API has changed pretty radically since 0.4.2...

seancorfield20:02:31

"Release 0.4.2 on 2015-09-15" <--

anler20:02:46

oh crap, yeah that is old 😄

seancorfield20:02:57

No wonder some of what I was suggesting you try didn't actually work 🙂

seancorfield20:02:13

BTW @inbox I'm surprised your :exclusions does anything if it's written as you showed -- org.postgresql isn't an artifact ID (maybe that excludes every artifact in that group? Seems unlikely).

anler21:02:33

@seancorfield yeah, isn't doing anything, because I just tried this code:

(jdbc/with-db-connection [con-spec {:dbtype "postgresql"
                                      :dbname "roc_test"
                                      :user "roc"
                                      :password "roc"
                                      :currentSchema "ns1"}]
    (jdbc/query con-spec ["SELECT * FROM users"]))
with these deps:
[org.postgresql/postgresql "42.0.0.jre7"]
[org.clojure/java.jdbc "0.7.5"]
and it works, but if I remove the [org.postgresql/postgresql "42.0.0.jre7"] then the select query uses the default schema :thinking_face: So clojure.java.jdbc doesn't have postgres jdbc driver as a dep? (sorry in advance for stupid questions, I'm new to all this artifact and deps in the java world)

anler21:02:48

my project also has this dependency: https://github.com/juxt/modular/blob/master/modules/postgres/project.clj#L9 that might bes the driver I'm using by default that doesn't support the currentSchema

seancorfield21:02:30

java.jdbc deliberately does not pull in any JDBC drivers -- you have to do that yourself (so you have full control over which one(s) you use).

seancorfield21:02:49

Per https://github.com/clojure/java.jdbc/blob/master/project.clj#L27-L28 those are just the driver versions I test against locally.

anler21:02:19

oh, ok, that I was looking at, hence my idea of the driver dep

seancorfield21:02:22

(the impossibl driver was a fairly recent addition in the test matrix)

seancorfield21:02:10

For Contrib projects, project.clj is not relevant -- it doesn't affect how the project is built.

seancorfield21:02:06

If you look in pom.xml (which is how Contrib projects are built) https://github.com/clojure/java.jdbc/blob/master/pom.xml#L90 you'll see all the drivers are marked a test scope...

anler21:02:31

awesome, well, running lein deps :tree I see the driver hanging from modular.postgres so that must be the one I believe I should exclude

seancorfield21:02:38

I may well replace project.clj with deps.edn instead since it's only useful for testing...

anler21:02:39

understood, well, thanks a lot for the help! I don't bother you anymore 🙂

seancorfield21:02:48

Feel free to bother me any time I'm around 🙂

seancorfield21:02:58

Which is general 9am Pacific to about 11pm Pacific 🙂

anler21:02:12

awesome, thanks a lot! 🙌