This document briefly explains how to access SQL databases from Eclipse. We illustrate with a PostgreSQL DB, then with a Derby database hosted in a GlassFish server.
Note
|
The reader supposedly has basic knowledge of JDBC and Eclipse. |
-
First, you need a JDBC driver, that Eclipse will use to access your DB. See here for PostgreSQL, or find the one you need for your DB type. (or
sudo apt-get install libpostgresql-jdbc-java
) -
Within Eclipse:
Preferences / Data Management / Connectivity / Driver Definitions
-
Register there your driver for PostgreSQL (or the DB type you need)
-
This does not create a connexion: it only declares a new driver definition, that is, a kind of connexion (that you will use in the next step)
-
Eclipse asks that you start with a template. Eclipse uses it to provide particular features for your DB type. (Unfortunately, JDBC is not a good enough abstraction and Eclipse has to know which flavor of SQL and protocol your DB implements.)
-
Choose the Eclipse template version that is the highest possible, but lower than or equal to your JDBC driver version (SO)
-
-
From the
Data Source Explorer
view, create a connexion to your DB (using the driver definition created previously) -
You can now view and edit data from the
Data Source Explorer
view -
You can write and send SQL commands from the
SQL Scrapbook
(with completion!)