How can I locate an embedded h2 db based on my SQuirrel configuration?

13,991

Solution 1

Based on the following value:

jdbc:h2:~/myDB;FILE_LOCK=NO"

It appears that your database file is located in your home directory in a file called myDB

The ~ denotes your home directory.

Solution 2

You can use the following code to run H2 in server mode and connect using SQuirrl SQL client.

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="org.h2.Driver" />
<property name="url" value="jdbc:h2:target/h2/ps;AUTO_SERVER=TRUE" />
<property name="username" value="sa" />
<property name="password" value="" />
</bean>

You can use SQuirrel SQL client (http://squirrel-sql.sourceforge.net/) to connect to you H2 database and look at the tables.

Create new connection. Select H2 in the driver dropdown menu Set url to your project target folder h2 folder (jdbc:h2:C:\projects\workspace\TestProject\target/h2/ps;AUTO_SERVER=true) Enter user name ("sa") Enter password ("")

Share:
13,991

Related videos on Youtube

membersound
Author by

membersound

JEE + Frameworks like Spring, Hibernate, JSF, GWT, Vaadin, SOAP, REST.

Updated on June 05, 2022

Comments

  • membersound
    membersound almost 2 years

    I have a simple h2 database example, I assume it is a database that is stored in a single file. But where do I find this file? I'd like to connect to that db using SQL clients like Squirrel. Where is this file placed by default?

        <property name="eclipselink.jdbc.platform"
            value="org.eclipse.persistence.platform.database.H2Platform" />
        <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
        <property name="javax.persistence.jdbc.url" value="jdbc:h2:~/myDB;FILE_LOCK=NO" />
        <property name="javax.persistence.jdbc.user" value="sa" />
        <property name="javax.persistence.jdbc.password" value="sa" />