Can't create in-memory database

Issue #146 new
Anonymous created an issue

I have tried "jdbc:sqlite::memory:" and "jdbc:sqlite:" and both create files on my root directory. All the code works, but I want the database to be "in-memory" and not on the filesystem.

Any suggestions?

Comments (5)

  1. Taro L. Saito repo owner

    I could't find the problem without seeing the code.

    Here is how to create memory database: Connection connection = DriverManager.getConnection("jdbc:sqlite::memory:");

  2. Tom Whitcomb

    Thanks for taking a look. I am doing it from clojure using lein.

    Here are my dependencies: dependencies [[org.clojure/clojure "1.6.0"] [org.clojars.amit/commons-codec "1.8.0"] [charset-bytes "1.0.0"] [ring/ring-core "1.3.0"] [ring/ring-jetty-adapter "1.3.0"] [compojure "1.1.6"] [org.clojure/java.jdbc "0.3.5"] ;[org.xerial/sqlite-jdbc "3.7.2"] [org.xerial/sqlite-jdbc "3.7.15-M1"] [digest "1.4.4"]

    Here is my connection string info:

    (def database {:classname "org.sqlite.JDBC" :subprotocol "sqlite" :subname "jdbc:sqlite::memory:" } )

    Every thing works OK except a "jdbc:sqlite::memory:" file is created on the file system.


  3. Ivan Grishaev

    You should get a connection by yourself:

    (declare db)
    (defn on-start []
      (let [db-uri "jdbc:sqlite::memory:"
            spec {:connection-uri db-uri}
            conn (jdbc/get-connection spec)]
        (assoc spec :connection conn)))
    (defn on-stop []
      (-> db :connection .close)
      ^{:on-reload :noop}
      :start (on-start)
      :stop (on-stop))
    (mount/start #'db)
    (jdbc/execute! db "create table users...")
    (jdbc/query db "select from users...")
    (mount/stop #'db)
  4. Log in to comment