How to connect to Database using Eclipse

Here we will learn to connect to any Database (Supported) using Eclipse IDE.

Step 1

Open Eclipse IDE and Select Database Perspective (Windows >> Open Perspective >> Other).

Eclipse IDE would look like below.

 

Step 2

Create Connection Profile: Here we will create profile for connecting to DB.

Method 1: Right click on “Database Connections” and click New.

Method 2: Click onNew Connection Profilebutton in “Data Source Explorer” view.

Step 3:

Select DB (Oracle in this case) to connect from popup window. And provide connection profile name (JBT in this case).

Click Next. In next screen provide DB connection details as shown below.

Once provide you can check if connection to DB is successful or not by clicking “Test Connection” button as shown above.

If everything is fine it should show Ping Succeed popup window as below. If not then check connection related details.

After providing the connection related details click Finish. If everything is fine then a new Connection profile named JBT will be created in Data Source Explorer view as show below.

Step 4: Execute Query

Here we will learn to execute query to DB and see the DB results. To execute a query you will require “SQL Scrapbook“.

To open SQL scrapbook click scrapbook button on top.

It will open new SQL scrap book, from there you can execute sql query. To view the result of the query fired you will require “SQL Results” view which can be opened from Windows >> Show View >> Other.
Keyboard shortcuts for executing query.

  • Execute All : CTRL+ALT+X
  • Execute Selected Text : ALT+X
  • Execute Selected Text as one statement : ALT+C

     

Step 6: Execution Plan

 

Execution plan of the query can also be checked via Eclipse IDE. To view Execution plan “Execution Plan” view needs to be opened. Eclipse IDE can show execution plan in two ways.

  1. Text Explain Plan
  2. Graphic Explain Plan

 

Text Explain Plan

Select the query and right click and select “Execute Text Explain Plan” menu. It will display explain plan as shown below.

Graphic Explain Plan

Select the query and right click and select “Execute Graphic Explain Plan” menu. It will display explain plan as shown below.

2 Comments

  1. Nice example..

    I am trying to connect with Postgres SQL its successful but with JSP page I trying to connect it but still the error is coming “java.lang.ClassNotFoundException: org.postgresql.Driver”

    Pls give detail example regarding the same.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.