简体   繁体   中英

How do I use clojure jdbc execute?

I'm struggling to get the jdbc/execute! function to commit any changes I make to my sqlite database.

For example,

user=> (jdbc/execute! sqlite-db ["insert into person (second_name) values ('Gandhi');"])
nil

nil is returned and the row is not inserted. However, I know the function is connecting to the database somehow because I can use an invalid table name and get an error:

user=> (jdbc/execute! sqlite-db ["insert into ABCDEFG (second_name) values ('Gandhi');"])

SQLException [SQLITE_ERROR] SQL error or missing database (no such table: ABCDEFG)  org.sqlite.DB.newSQLException (DB.java:383)

The jdbc library also includes a jdbc/insert! function, and I can insert correctly using this. However, I wanted to use the execute! function instead because in my application I use a more complex statement and I thought I would therefore supply a parameterized sql string.

Where am I going wrong using the execute! function?

At the time of this answer -> Using execute! with no params to insert a row fails on SQLite <- is listed as still an open issue to be resolved in beta 0.3.0 of java.jdbc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM