h2 named database schema not found

Viewed 31

when I create h2 memory database with a "name", I can't seem to use the name to refer to the table and keep getting "schema not found". Any idea?

val con = DriverManager.getConnection("jdbc:h2:mem:mytest;MODE=MYSQL;DATABASE_TO_UPPER=false;DB_CLOSE_DELAY=-1")
    val stm = con.createStatement

    val sql: String =
      """
        |create table mytest.test_table1(ID INT PRIMARY KEY,NAME VARCHAR(500));
        |insert into mytest.test_table1 values (1,'A');""".stripMargin

    stm.execute(sql).result
    ```

Exception in thread "main" org.h2.jdbc.JdbcSQLSyntaxErrorException: Schema "mytest" not found; SQL statement:

create table mytest.test_table1(ID INT PRIMARY KEY,NAME VARCHAR(500));
insert into mytest.test_table1 values (1,'A'); [90079-199]
1 Answers
  1. ;MODE=MYSQL;DATABASE_TO_UPPER=FALSE is only suitable for H2 1.4.197 and older versions. For H2 1.4.198 Beta and newer versions you need to use MODE=MySQL;DATABASE_TO_LOWER=TRUE instead, otherwise all identifiers will be case sensitive, unlike in MySQL.
  2. Database name is not related to the schema name in H2. By default, there is only PUBLIC schema for your tables. If you need a different schema, you need to create it first with standard CREATE SCHEMA mytest; command.

Please also note that H2 1.4.199 is an old unsupported version of H2 database.

Related