3

This is what I have tried, starting with clojure.java.jdbc and a map containing the 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 I tried to use execute but it cannot use the given connection configuration because the database does not yet exist:

(j/execute! mysql-db "CREATE DATABASE changelog_development") ;; MySQLSyntaxErrorException Unknown database 'changelog_development'    

So I remove that dbname key and tried again, however the error says I have a missing parameter:

(j/execute! (dissoc mysql-db :dbname) "CREATE DATABASE changelog_development") ;; IllegalArgumentException db-spec {:dbtype "mysql", :user "root", :password "", :useSSL true, :verifyServerCertificate false} is missing a required parameter  

1 Answer 1

5

clojure.java.jdbc connection spec has many possible formats. The one with keys for :dbtype, :user etc requires that you also specify a :dbname.

You can also specify your connection spec using a connection URI instead and execute your statement again:

{:connection-uri "jdbc:mysql://localhost/?user=root&password="}

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.