Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
186 views
in Technique[技术] by (71.8m points)

java - Inspect in memory hsqldb while debugging

We're using hdsqldb in memory to run junit tests which operate against a database. The db is setup before running each test via a spring configuration. All works fine. Now when a tests fails it can be convinient to be able to inspect the values in the in memory database. Is this possible? If so how? Our url is:

jdbc.url=jdbc:hsqldb:mem:testdb;sql.enforce_strict_size=true

The database is destroyed after each tests. But when the debugger is running the database should also still be alive. I've tried connecting with the sqldb databaseManager. That works, but I don't see any tables or data. Any help is highly appreciated!

question from:https://stackoverflow.com/questions/2697341/inspect-in-memory-hsqldb-while-debugging

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In your unit test or in the @Before / setUp() method, you can add the following line to launch the HSQL Database Manager:


org.hsqldb.util.DatabaseManager.main(new String[] {
  "--url",  "jdbc:hsqldb:mem:testdb", "--noexit"
});

or for the improved Swing version with "more refinements" (but about same functionality)


org.hsqldb.util.DatabaseManagerSwing.main(new String[] {
  "--url",  "jdbc:hsqldb:mem:testdb", "--noexit"
});

The DB manager lets you inspect your schema and run SQL queries on the live in-memory database while the application is running.

Make sure to set a beakpoint or pause the execution one way or another if you want to check the state of your database at a specific line.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...