H2 console - looking at the database via browser shows old data

不打扰是莪最后的温柔 提交于 2020-01-05 07:27:09

问题


I'm using H2 database for a simple web application.

When I try and view the data via the H2 console web browser, it doesn't seem to update with the latest data in the database.

For example:

I add a new record to a table using my web app and when I do a select * from the table I added the record to, it doesn't show the new record.

I have the following settings for the Login when I connect to H2 console via the browser:

Saved Settings: Generic H2 (Embedded)

Setting Name: Generic H2 (Embedded)

Driver Class: org.h2.Driver

JDBC URL: jdbc:h2:file:/Develops/Databases/snowy_db;FILE_LOCK=NO

Any ideas on how I go about accessing the latest data from the database using the H2 console browser?

Thanks in advance.

Edit

Just to add: I can see the new record in my web app but not when I use the H2 console browser.


回答1:


I guess your problem is FILE_LOCK=NO option. The documentation states about it that:

it is up to the application to protect the database files. Failing to do so will result in a corrupted database. [...] Please note that this is unsafe as another process is able to open the same database, possibly leading to data corruption

I am strongly recommending you to use more sophisticated H2 mode like automatic mixed mode. In this mode the first application that connects to a given database opens a socket server and every subsequent attempt to connect to this database from other applications uses socket connection rather than raw file system access.

If you don't feel comfortable with that, just run H2 as a standalone server separately or inside your Seam application. Then change your JDBC URL so that it connects via localhost and TCP connection.



来源:https://stackoverflow.com/questions/5019271/h2-console-looking-at-the-database-via-browser-shows-old-data

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!