Fork me on GitHub
#sql
<
2020-05-18
>
j16:05:03

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

seancorfield16:05:20

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

seancorfield16:05:04

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.

j17:05:27

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

j17:05:22

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"])

dpsutton17:05:04

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

j18:05:29

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

seancorfield18:05:17

@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).

seancorfield18:05:42

Ah, I see you found that in the docs.

dpsutton18:05:52

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

dpsutton18:05:07

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

j18:05:53

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

dpsutton18:05:00

haha thanks

dpsutton17:05:22

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

dpsutton17:05:12

> 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).

j17:05:46

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