Is there a way to browse the content of an H2 or an HSQLDB in-memory database for viewing? For example, during a debugging session with Hibernate in order to check when the flush is executed; or to make sure the script that instantiates the DB gives the expected result.
Does it exist an addon or a library that you can embed with your code in order to allow this?
Please, mention which one you're talking about (H2 or HSQLDB) in case you have an answer specific to one of them.
I don't know why is it working fine at yours machines, but I had to spend a day in order to get it is working.
The server works with Intellij Idea U via url "jdbc:h2:tcp://localhost:9092/~/default".
"localhost:8082" in the browser alse works fine.
I added this into the mvc-dispatcher-servlet.xml
You can run H2 web server within your application that will access the same in-memory database. You can also access the H2 running in server mode using any generic JDBC client like SquirrelSQL.
UPDATE:
Now you can connect to your database via
jdbc:h2:mem:foo_db
URL within the same process or browse thefoo_db
database usinglocalhost:8082
. Remember to close both servers. See also: H2 database in memory mode cannot be accessed by Console.You can also use Spring:
BTW you should only depend on assertions and not on manual peeking the database contents. Use this only for troubleshooting.
N.B. if you use Spring test framework you won't see changes made by a running transaction and this transaction will be rolled back immediately after the test.
This is a Play 2 controller to initialize the H2 TCP and Web servers:
For H2, you can start a web server within your code during a debugging session if you have a database connection object. You could add this line to your code, or as a 'watch expression' (dynamically):
The server tool will start a web browser locally that allows you to access the database.
I've a problem with H2 version 1.4.190 remote connection to inMemory (as well as in file) with
Connection is broken: "unexpected status 16843008"
until do not downgrade to 1.3.176. See Grails accessing H2 TCP server hangsIn H2, what works for me is:
I code, starting the server like:
That starts the server on
localhost
port 9092.Then, in code, establish a DB connection on the following JDBC URL:
While debugging, as a client to inspect the DB I use the one provided by H2, which is good enough, to launch it you just need to launch the following java main separately
This will start a web server with an app on 8082, launch a browser on
localhost:8082
And then you can enter the previous URL to see the DB