3

I'm trying to use clojure.java.jdbc to insert rows into a database. (The database in question is sqlite).

I can create a table like this:

(def db {:classname "org.sqlite.JDBC"
         :subprotocol "sqlite"
         :subname "/path/to/my/database"})

(with-connection db (create-table :foo [:bar :int] 
                                       [:baz :int] 
                                       [:timestamp :datetime]))

And this works. But if I try to insert a row into the database, this fails:

(with-connection db (insert-rows :foo
          [1 2 (java.sql.Timestamp. (.getTime (java.util.Date.)))]))

Giving an exception: assertion failure: param count (3) != value count (6).

But if I omit the timestamp field from the table definition and insert-rows operation, there isn't a problem. So what am I doing wrong with the timestamp?

1 Answer 1

3
 (def sqllite-settings
  {
   :classname   "org.sqlite.JDBC"
   :subprotocol "sqlite"
   :subname     "test.db"
  }
 )

(with-connection sqllite-settings 
  (create-table :foo 
        [:bar :int] 
        [:baz :int]  
        [:timestamp :datetime]))

(with-connection sqllite-settings (insert-rows :foo
       [1 2 (java.sql.Timestamp. (.getTime (java.util.Date.)))]))

(with-connection sqllite-settings 
       (with-query-results rs ["select * from foo"] (doall rs)))

returned the expected:

({:bar 1, :baz 2, :timestamp 1311565709390})

I am using clojure.contrib.sql

(use 'clojure.contrib.sql)

And the SQLLite driver from here: http://www.zentus.com/sqlitejdbc/

Can you try if contrib.sql works for you ?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.