Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Hibernate Basics Persisting Data with Hibernate Updating and Deleting Entities

Can the H2 database be accessed via a terminal?

Is it possible to view the database created using Hibernate via the terminal?

Thanks!

2 Answers

Alexander Nikiforov
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,175 Points

No, I think it is not possible.

http://www.h2database.com/html/main.html

Postgresql and Sqlite and others have that feature I think, but not H2 database.

H2 has a nice GUI feature.

Have you watched Chris 'Spring with Hibernate' video:

https://teamtreehouse.com/library/create-a-sessionfactory-and-datasource

In this video, Chris starts his database as a server database, so URL should be different.

But for testing purposes, and if you are beginner, it is better to fire up server base database.

So your hibernate.cfg.xml should be changed to

<hibernate-configuration>
    <session-factory>
        <!-- Database connection setting -->
        <property name="connection.driver_class">org.h2.Driver</property>

       <!-- server based database -->
        <property name="connection.url">jdbc:h2:tcp://localhost/./data/contactmgr</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.H2Dialect</property>

        <!-- Update the database schema on startup -->
        <property name="hbm2ddl.auto">update</property>

        <!-- Show the queries prepared by Hibernate -->
        <property name="show_sql">true</property>

        <!-- Names the annotated entity classes -->
        <mapping class="com.teamtreehouse.contactmgr.model.Contact" />
    </session-factory>
</hibernate-configuration>

You can also see GUI for embedded database by running java -jar h2*.jar, but it can be problematic with embedded databases because, embedded databases allow ONLY one connection, i.e. you cannot use database in your Java Application and simultaneously use GUI to see your database.

Anyway. All information is here:

http://www.h2database.com/html/cheatSheet.html

And please watch Chris video, disregard Spring details, just see how he fires up H2 database GUI console

Thank you!