How to create new database in H2 database

H2 database is a lightweight, embeddable SQL database implemented in Java. In H2 each database is stored in a file, the database name is same as the file name. Whenever you connect to a database, it's created automatically if the file didn't exist.

The connection implicitly created database for you. All the subsequent queries are executed in that database.

If you execute create database hello command you will get a syntax error

Execute following Clojure code in REPL

(require '[ :as j])
(def demo-settings
    :classname   "org.h2.Driver"
    :subprotocol "h2:mem"
    :subname     "demo;DB_CLOSE_DELAY=-1"
    :user        "sa"
    :password    ""
(j/execute! demo-settings ["show databases"])

And the error will look like the following

If you want to create new database, just change the connection string, for example I want to create a new database with name "hello", use the following connection string

conn = DriverManager.getConnection("jdbc:h2:~/hello", "", "");