Monday, December 8, 2014

How to add oracle DB connection in Eclipse

Have a DB connection in Eclipse will be very helpful if you need use persistence frameworks like Hibernate or JPA.  It's normally a prerequisite for other functions, for example let eclipse create java entities class from database tables automatically.  Here's how to configure oracle connection in Eclipse.

1. what you need

  • Oracle JDBC driver. ( A jar file may look like ojdbcxxx.jar, if you don't have it on your local file system, download it from oracle website)

2. open "Data Source Explorer" view in Eclipse

From menu, select "window"->"Show View"->"Other"

Snap_2014.12.09 11.23.04_014

Next, Choose "Data Source Explorer" from category "Data Management"

Snap_2014.12.09 10.04.24_002

Then you should have the view opened.

3. Add new connection

Right click on the "Database Connection" in the "Data Source Explorer" view we just opened.  choose "New..."

Snap_2014.12.09 10.06.49_003 

Choose database type ( here is Oracle), give a name for this connection (here is "oracle")

Snap_2014.12.09 10.08.52_005

Next, select the oracle driver for this connection by click the follow icon pointed by the arrow.

Snap_2014.12.09 10.13.26_006

Next, choose oracle version (I'm using oracle 11 for this demo, you can pick up your version) ,  and click the "Jar List" tab to set the driver file path

Snap_2014.12.09 10.14.51_007

In the "Jar List" tab, replace the default non-exists oracle driver file, which is ojdbc14.jar, with the real one  in you local file system, which is d:\ojdbc6.jar

Snap_2014.12.09 10.17.27_009

Snap_2014.12.09 10.19.15_010 

Close the above window,  next provide connection information.

Snap_2014.12.09 10.22.01_012

Use "Test Connection" button to make sure every thing is OK, then Finish.

4. After Connection created

You can see the new oracle DB connection appears in the "Data Source Explorer" view.

Snap_2014.12.09 11.50.04_015

You can browse the database in the view within Eclipse.

8 comments:

  1. Works for me too. Thanks!
    It could be useful just to explain "SID" property.

    ReplyDelete
  2. after doing all this it shows ping failed msg how we can resolve it

    ReplyDelete
  3. I am using informix, and version 12 is not shown I can do?

    ReplyDelete
  4. Nice article, worked for me as well

    ReplyDelete
  5. In drivers tab, i can't see any specified drivers

    ReplyDelete
  6. Doesn't this driver definition need to know where my ORACLE_HOME is? How does it know how to translate the SID? We use ldap here and it's defined very nicely in the usual place in the ORACLE_HOME/network/admin.

    Or does the jdbc driver not need it?

    I feel I'm missing a significant piece of information....

    ReplyDelete

Powered by Blogger.

About The Author

My Photo

Has been a senior software developer, project manager for 10+ years. Dedicate himself to Alcatel-Lucent and China Telecom for delivering software solutions.

Pages

Unordered List