Setup Oracle Database Connection in Eclipse

To setup Oracle Database Connection in Eclipse is very much similar to any other Databases. There are 3 steps you need to follow.

Install Oracle Database

Since I didn’t find a non-install Oracle Database package, I assume that there is no such thing. So you have to install it, which takes a little bit more time but makes it way easier to setup.

  1. Download from Oracle (the link might be changing over time, just search on google)
  2. Install it

Note, for 11g express, the default Database Service Name is XE. To check that out, execute the following code in SQL Command Line.

select value from v$parameter where name like '%service_name%';

Oracle Database shipped with a cheapo Command Line tool which you can find once the installation finished. You can type connect or conn in it to connect to database.

Install Oracle Database Driver in Eclipse

You need to download Oracle Database Driver first.

Then in the Eclipse, open Preferences, and go to Data Management -> Connectivity -> Driver Definitions. You should probably not find any Oracle drivers there if you didn’t install Oracle Database Tools previously. Click add, it will pop up a dialog asking you what driver template you want to use. Again, if you don’t have Oracle Database Tools installed, you would just see Oracle Database Driver for 10g, Oracle Thin Driver for 8g to 11g and Other Driver for 8g to 11g. I found it doesn’t really matter to choose either one, but I choosed Thin Driver for 11g just because I’m using 11g. Switch to JAR List tab, and add JAR/ZIP you just download. Leave properties there, and done.

If you ever installed Oracle Database Tools, you’ll be having drivers installed. I’ll talk about that in another article: Introduction of Oracle Database Tools.

Setup Database Connection

Switch to Database Development Perspective and you will find Data Source Explorer window. Right click on Database Connections folder -> new. Choose the Oracle then next. Choose the driver you created earlier and fill out the properties as follows:

SID:xe
Service name:XE (ether one works by default)
Host: localhost
Port number: 1521
User name: SYSTEM (you can change users if you want)
Password: the password you set when installing the database (or created with your other users)
Connection URL: jdbc:oracle:thin:@localhost:1521:xe (auto complete, don't change)

You can try connection before created. If everything is right, you should be good to go.

Introduction of Oracle Database Tools

A Brief Description why you want Oracle Database Tools

This article will introduce you how to setup a GUI for your oracle database in Eclipse with Oracle Database Tools.

Note that most Databases actually have their own GUI tool programs, but Oracle 11g express is not shipped with one. For general purposes with almost every database, you can use Beaver DB, which is a really good tool you can also find in Eclipse Marketplace. But Oracle Database Tools are optimized specifically for Oracle DB, means they give you more capabilities to work with Oracle DB.

Installation

To setup Oracle Database Tool, go to Eclipse Marketplace within your Eclipse. Search Oracle Database Tools, and you will find it. It is developed by Oracle, and is free.

Once you done installation, you’ll find some icons in the Data Source Explorer are actually changed. If you haven’t setup Database Connection yet, check Setup Oracle Database Connection in Eclipse.

Start using it

If you have tables created by users other than SYSTEM, and you logged in using SYSTEM, you can find the tables under that user’s schema (the schema name is the user’s name). The following SQL code shows how to create a user:

CREATE USER <username> IDENTIFIED BY <password>
DEFAULT TABLESPACE users;
GRANT [privileges] TO <username>;

Once you created a user, you can expand that user’s schema in the hierarchy and explore all the contents of it. By right click on Tables and Edit Schema, you can view and edit the physical ERD of all tables this user has. The Tools can actually generate DDL as you editing the table on GUI.