How to create a database using JDBC in Clojure? -
this have tried, starting clojure.java.jdbc , map containing database connection details:
(:require '[clojure.java.jdbc :as j])) (def mysql-db {:dbtype "mysql", :dbname "changelog_development", :user "root", :password "", :usessl true, :verifyservercertificate false}
first tried use execute cannot use given connection configuration because database not yet exist:
(j/execute! mysql-db "create database changelog_development") ;; mysqlsyntaxerrorexception unknown database 'changelog_development'
so remove dbname
key , tried again, error says have missing parameter:
(j/execute! (dissoc mysql-db :dbname) "create database changelog_development") ;; illegalargumentexception db-spec {:dbtype "mysql", :user "root", :password "", :usessl true, :verifyservercertificate false} missing required parameter
clojure.java.jdbc
connection spec has many possible formats. 1 keys :dbtype
, :user
etc requires specify :dbname
.
you can specify connection spec using connection uri instead , execute statement again:
{:connection-uri "jdbc:mysql://localhost/?user=root&password="}
Comments
Post a Comment