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

  1. Click Download.
  2. Extract the contents of the archive
    $ unzip jboss-eap-quickstarts-<version>.zip
  3. Copy the h2console.war file to the JBoss EAP 6.x deployments directory
    $ cp jboss-eap-quickstarts-<version>/h2-console/h2console.war /path/to/jboss-eap/standalone/deployments/
  4. Confirm the H2 console web application is running by looking at the server output in the Console view in JBoss Developer Studio.
    The deployment of the H2 console web application can be confirmed by looking at the server output in the Console tab in JBoss Developer Studio.

    Figure 2.15. Console Output showing h2console.war Deployed

  5. In the IDE open a new Web Browser by clicking WindowShow ViewOther, expand General and double-click Internal Web Browser.
  6. In the address bar of the Web Browser, enter http://localhost:8080/h2console.
  7. In the Login area, in the JDBC URL field type jdbc:h2:mem:ticket-monster and in both the User Name and Password fields type sa. These settings are defined in the ticket-monster-ds.xml file in the ticket-monster/src/main/webapp/WEB-INF directory.
    In the address bar of the Web Browser, enter http://localhost:8080/h2console. In the Login area, type jdbc:h2:mem:ticket-monster in the JDBC URL field and type sa in both the User Name and Password fields.

    Figure 2.16. Completed H2 Login Web Page

  8. Click Connect to 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 Run. 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.
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 Run. 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

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.