sql

All things SQL and JDBC...
j 2020-05-18T16:19:03.488700Z

what's the proper syntax for next.jdbc :dbname db spec for indicating a sqlite local file that lives in resources/dbfile.db? :dbname "resources/dbfile.db" doesn't seem to work

seancorfield 2020-05-18T16:49:20.489500Z

@watchtheblur Can you expand on "doesn't seem to work"? When I tried that, it works.

seancorfield 2020-05-18T16:51:04.490Z

user=> (def ds (jdbc/get-datasource {:dbtype "sqlite" :dbname "resources/dbfile.db"}))
#'user/ds
user=> (jdbc/execute! ds ["select 1 as foo"])
[{:foo 1}]
user=> 
This creates resources/dbfile.db as expected for me.

j 2020-05-18T17:16:27.490900Z

I get the following error when I use code similar to yours (with the filename different):

(jdbc/execute! ds ["select 1 as foo"])
Execution error (SQLException) at java.sql.DriverManager/getConnection (DriverManager.java:689).
No suitable driver found for jdbc:sqlite:resources/rmfetch.db

j 2020-05-18T17:17:22.491500Z

Here's my code:

(def db {:dbtype "sqlite" :dbname "resources/rmfetch.db"})
(def ds (jdbc/get-datasource db))
(jdbc/execute! ds ["select 1 as foo"])

dpsutton 2020-05-18T17:19:04.492100Z

I don't see it explicitly called out in the docs https://cljdoc.org/d/seancorfield/next.jdbc/1.0.424/doc/getting-started but in addition to next.jdbc you need the actual driver that will be used to connect to the db

dpsutton 2020-05-18T17:19:22.492700Z

note in hte example there he is using com.h2database/h2.

dpsutton 2020-05-18T17:20:12.493Z

> In addition, you will need to add dependencies for the JDBC drivers you wish to use for whatever databases you are using. You can see the drivers and versions that `next.jdbc` is tested against in https://github.com/seancorfield/next-jdbc/blob/master/deps.edn#L11-L24`deps.edn`https://github.com/seancorfield/next-jdbc/blob/master/deps.edn#L11-L24, but many other JDBC drivers for other databases should also work (e.g., Oracle, Red Shift).

j 2020-05-18T17:20:46.493900Z

I am indeed missing that in my deps.edn. Thanks @dpsutton I'll try that now

j 2020-05-18T18:17:29.494100Z

It was the driver line that was missing. Thanks again @dpsutton and @seancorfield. I went back and read the link above and the last paragraph under "Installation" shows how to put in the driver line.

seancorfield 2020-05-18T18:26:17.494300Z

@dpsutton The last paragraph of the Installation section says: > In addition, you will need to add dependencies for the JDBC drivers you wish to use for whatever databases you are using. You can see the drivers and versions that next.jdbc is tested against in the project's deps.edn file, but many other JDBC drivers for other databases should also work (e.g., Oracle, Red Shift).

seancorfield 2020-05-18T18:26:42.494500Z

Ah, I see you found that in the docs.

dpsutton 2020-05-18T18:26:52.494700Z

yeah i was trying to mark out my responses. and i quoted that after i saw it 🙂

dpsutton 2020-05-18T18:27:07.494900Z

i couldnt' figure out the right sequence of tilde's to mark through my text 🙂

seancorfield 2020-05-18T18:27:26.495100Z

Gotcha!

j 2020-05-18T18:27:53.495300Z

I saw him do it live so I can testify to its veracity 😉

dpsutton 2020-05-18T18:28:00.495500Z

haha thanks