How to access H2 Database

HOW TO ACCESS H2 DATABASE USING DBVISUALIZER:

  • I am using dbVisualizer to open h2 database. Goto tools–>driver manager–>select driver name (h2) then, add h2-1.3.176.jar from your file location. And you also have to do it for (h2 embedded) driver in there.
  • First I make backup copy of the database mydb-prodD.h2.db.bck in another location. Then I tried to access the database named [mydb-prodD.h2.db] which I currently placed in this location i.e. E:testdbmydb-prodD.h2.db . I am using dbVisualizer (free edition). But while putting the name in the JDBC URL, please do not put [h2.db] extension with it.

 

 

 

  • Now whole URL name for accessing my H2 database is [E:testdbmydb-prodD;AUTO_SERVER=TRUE;MODE=MYSQL;LOCK_MODE=0;DB_CLOSE_DELAY=-1 ].

Now we will see all the generated user or default table in there.

h2 db access

h2 db access

HOW TO ACCESS H2 DATABSE USING BROWSER MODE:

My h2 server is located at C:h2-2014-04-05h2binh2.bat. Now if I try to access it by running [C:h2-2014-04-05h2binh2.bat] it will open a browser window.

1) Change the Saved settings to [GENERIC H2 EMBEDDED/SERVER]

2) Put DRIVER CLASS to [org.h2.Driver]

3) Put jdbc url to: [jdbc:h2: E:testdbmydb-prodD] , Then put username: sa

Now if u try to connect, it will suggest you to connect using [server mode] via a url like [140.184.199.243:51374/1581adcdd94c1d8ea489983ddfd22833c1e7fb30e1a].

4) Now try again by changing some settings in the browser window like

Saved settings: GENERIC H2 SERVER

JDBC URL: jdbc:h2:tcp://140.184.199.243:51374/1581adcdd94c1d8ea489983ddfd22833c1e7fb30e1a

Now press connect.

THE MOST INTERESTING PART IS NOW WE CAN CONNECT TO THIS DATABASE ANYTIME USING THIS URL (until you shutdown /totally logoff from your computer). BECAUSE USING DBVISUALIZER IT MAKES THE DATABASE INACCESSIBLE WITHOUT ANY REASON.

Now you can see all available (generated table) data of that database.