2.9. Access and Query the Database
This web project uses the in-memory database, H2, of the application servers in JBoss EAP 6.x. The H2 console web application can be used to access the H2 database but this is not packaged with JBoss EAP 6.x. As the procedure below explains, the H2 console web application must be downloaded and deployed on the application server from outside JBoss Developer Studio before the H2 database can be accessed.
Procedure 2.9. Access and Query the Database
- Click.
- Extract the contents of the archive
$ unzip jboss-eap-quickstarts-<version>.zip
- Copy the
h2console.war
file to the JBoss EAP 6.xdeployments
directory$ cp jboss-eap-quickstarts-<version>/h2-console/h2console.war /path/to/jboss-eap/standalone/deployments/
- Confirm the H2 console web application is running by looking at the server output in the Console view in JBoss Developer Studio.
Figure 2.15. Console Output showing
h2console.war
Deployed - In the IDE open a new Web Browser by clicking → → , expand General and double-click Internal Web Browser.
- In the address bar of the Web Browser, enter http://localhost:8080/h2console.
- In the Login area, in the JDBC URL field type
jdbc:h2:mem:ticket-monster
and in both the User Name and Password fields typesa
. These settings are defined in theticket-monster-ds.xml
file in theticket-monster/src/main/webapp/WEB-INF
directory.Figure 2.16. Completed H2 Login Web Page
- Clickto connect to the database.
The
Event
, Member
and Venue
entities created in the TicketMonster project are displayed under jbdc:h2:mem:ticket-monster. Expanding the entities shows the fields associated with each. The records stored in the database are viewed using SQL search statements. For example, to display all the Event records stored in the database, click Event, which creates a SQL search statement based on Event in the SQL statement field, and click . The details of the Event sample records you added to import.sql
earlier in the tutorial are visible in the table below the SQL statement field.
Figure 2.17. Event Records Stored in the H2 Database