I have a problem with connecting to H2 in memory DB from H2 console. I am not using the Spring - just pure Java EE. I am specifying the H2 connection string in persistence.xml file:
<persistence-unit name="testPersistenceUnit" transaction-type="JTA">
<jta-data-source>jdbc:h2:mem:testdb</jta-data-source>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE" />
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
</properties>
Then when the application is started in one of my servlet I am starting the TCP and Web H2 servers:
Server.createWebServer("-web", "-webAllowOthers", "-webPort", "8082").start();
Server.createTcpServer("-tcp", "-tcpAllowOthers", "-tcpPort", "9092").start();
Then I try to open localhost:8082 and enter the info which is required for connection:
- Driver class: org.h2.Driver
- JDBC URL: jdbc:h2:mem:testdb
First problem I see - it does not matter which user / password I put - connection is always successful. Another problem - when I press Connect I do not see any of my tables. I know it is easy with Spring support. However, solutions which I found do not work for Java EE application.