开发者

Access mem or fs database tables using H2 console

开发者 https://www.devze.com 2023-03-12 01:05 出处:网络
I\'m trying to access my application\'s tables in Play! Framework,开发者_运维问答 but I can\'t find it using the console.

I'm trying to access my application's tables in Play! Framework,开发者_运维问答 but I can't find it using the console. For instance, I have two entity models: Address and Campus.

I can create objects and save normally, but I would like to see the changes in fs or mem DB, but the H2 console doesn't show the tables Address and Campus. I'm using the default settings to log in localhost:9000/@db.

What am I doing wrong?

Thanks in advance.


The correct URL for the inmemory database is:

jdbc:h2:mem:name-of-your-play-db


Steps I took to get a filesystem H2 database console working where my app is in c:\play\myapp:

  1. Go to localhost:9000/@db
  2. Choose the Generic H2 Server option in the first box
  3. For the url enter jdbc:h2:file:c:/play/myapp/db/h2/play
  4. Username is sa password is blank


Most likely the problem is the database URL, so your application and the H2 Console are using different databases. I suggest to use a database URL of the form jdbc:h2:~/data/test or (maybe even better) using an absolute path of the form jdbc:h2:/data/test, or when using Windows even with drive letter: jdbc:h2:c:/data/test. See the documentation about where the database files are stored.


My five cents. In my case (Unix OS) I just managed to make it work using ~/ in my persistence.xml:

<property name="javax.persistence.jdbc.url" value="jdbc:h2:~/data/testxdb" />

In this way the Database was created in: /Users/lm2a/data/testxdb.mv.db and starting the console with

java -jar h2-2.1.214.jar

Finally I could see my Tables.

0

精彩评论

暂无评论...
验证码 换一张
取 消