Home >Java >javaTutorial >Why does my H2 in-memory database show a \'Table not found\' error after creating a table?

Why does my H2 in-memory database show a \'Table not found\' error after creating a table?

Patricia Arquette
Patricia ArquetteOriginal
2024-10-29 17:38:02789browse

Why does my H2 in-memory database show a

Table Not Found in In-Memory H2 Database

When connecting to an H2 database in memory using the "jdbc:h2:mem:test" URL, users may encounter a "Table not found" error despite creating the table previously. This anomaly arises due to H2's default behavior of closing the connection after DDL operations, leading to the table becoming inaccessible.

Solution:

To remedy this issue, modify the connection URL by appending ";DB_CLOSE_DELAY=-1" to keep the database open persistently, preventing the table from being discarded. The modified URL should look similar to this:

jdbc:h2:mem:test;DB_CLOSE_DELAY=-1

By incorporating this change, H2 will retain the database content until the virtual machine is terminated, ensuring that any created tables remain intact.

The above is the detailed content of Why does my H2 in-memory database show a \'Table not found\' error after creating a table?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn