Database perspective in Eclipse and connecting to DB from Eclipse

Eclipse offers graphical interface for database administration; it is called Database Development Perspective.

1. Open Database Development Perspective

Go to menu Window > Open Perspective > Other > select Database Development Perspective from the list of perspectives and click OK.

Eclipse windows are changed and reorganized to give the user a better overview over Database management tools. The left window is called Data Source Explorer. Later you will see a list of available database connections here. So let’s make the first Database Connection, but before make sure that Database is up and running.

2. Create new Database Connection

Right click on the Database Connections directory and select New option. A New Connection Profile window is opened.

Select connection profile type (in my case Derby) and enter the name for new database connection (eg. MyDerbyDb) and click Next.

3. Specify a Driver and Connection details

You need to specify database driver and connection parameters. From the Drivers drop-down menu select a suitable driver to connect to DB. If the drop-down menu is empty, you need to add the driver first. See (3a) for details on driver definition, otherwise you can skip this step and continue reading step (3b).

3a. Driver Definition

Click on the rounded icon next to the drop-down menu. New window Edit Driver Definition is opened. In the first tab Name/Type set the custom name of database driver. Switch to the second tab JAR List and add jars that your database driver will need to operate. Since I am using Derby DB, I have to add derbyclient.jar file.

3b. Edit properties

In Database field enter the path to the database. Set hostname of the server where DB is running and port where DB is listening for connections. Set the username and password as well. Below you can see the URL where you can access DB via jdbc driver (from Java application or from some other DB client).
Click Next to see a preview of connection details, or click Finish.

4. Finish

In Data Source Explorer window you should see new database connection item. You should be already connected to the DB, otherwise right click on the DB item and select Connect.

5. Browse the Database

Browse the DB within Data Source Explorer window. By right clicking on the table in database you can browse or edit data. Create and execute SQL scripts.
The results will be displayed in the SQL Results window.