- This tutorial explains how to configure H2 database connection profile using Eclipse DTP and use Eclipse Data Source Explorer to connect to, navigate, and interact with datasource resources associated with the selected connection profile.
Eclipse DTP Plugin
- The Eclipse Data Tools Platform (DTP) project provides set of frameworks and tools for creating, managing, and performing database development and SQL query functions.
- The DTP plugin supports several database platforms including DB2, MySQL, HSQLDB, Derby, SQLite, Oracle, MS SQL, Postgres, Sybase ASA, Flat Files, XML Data, Web Services, and more.
- This project includes tools for specific data sources, connection-management functionality, Data Source Explorer view and query tools necessary to build, access, and manipulate data.
- Eclipse Indigo/Juno IDE for Java EE Developers (To install Eclipse, refer this link)
- H2 database JAR file
Download H2 database JAR file
- The JAR file can be downloaded from: http://www.h2database.com/html/download.html
Database Development Perspective
To create connection profile, you need to be in Java EE perspective or in Database Development perspective.
- To open database development perspective, click on Open Perspective icon from right top corner and click on Other…
- Select Database Development and click on OK.
Creating Connection Profile:
Connection profile can be created in one of the following ways;
- Right click on Database Connections in Data Source Explorer -> New
- From the main menu, select File -> New -> Other. Under Connection Profiles, select Connection Profile and click Next.
- Select Generic JDBC from Connection Profile Types
- Enter a unique Name for the connection profile.
- (Optional) Enter a Description.
- Click Next.
Now select an existing JDBC Driver and provide Connection Details in the “New Connection Profile” dialog.
If this is the first installation of H2 Database Profile in your Eclipse workspace, you have to create a new driver definition by providing the location of the driver JAR and connection properties.
- Click on the New Driver Definition icon next to the Drivers combo box.
- Select driver version under Name/Type tab.
- Click on JAR list tab and add the location of the H2 database JAR file.
- Click on Properties tab and enter the properties and click on OK.
- Here ~ in the connection URL refers to the user’s home directory location or if you want to enter a specific location such as your project directory you can use “jdbc:h2:file:///C:Users/iByteCode/projectWorkspace/Project1/db/testdb”.
- Browse for the driver class (org.h2.Driver), enter the User ID as “sa” (empty password) and click on OK.
- Click Test Connection to ping the server and to verify that the connection profile is working.
- Click Finish to create the connection profile.
This creates “testdb.h2.db” in the specified location.