Configure database connection in Eclipse

  • 04 July 2016
  • ADM

 

Configure database connection in Eclipse - images/logos/eclipse.jpg

 

The Eclipse Data Tools Platform (DTP) provides tools to connect and do database operations.

In this tutorial I used:

  • Eclipse (for Java EE Developers)
  • MariaDB 5.5
  • MySQL Java Connector version 5.1.39

You can do this very easy by following the next steps.

Step1

From File-->New-->Other... select Connection Profiles and click Next.

Configure database connection in Eclipse - /images/EclipseDBConnection01.png

Step2

From the next wizard window, select your database type, in my case MySQL.

Configure database connection in Eclipse - /images/EclipseDBConnection02.png

Step3

Before being able to connect to the database we need to configure a database driver. To do this click the New Driver Definition button (+).

Configure database connection in Eclipse - /images/EclipseDBConnection03.png

Select the database driver type and type a driver name - I will use the driver version as suffix.

Configure database connection in Eclipse - /images/EclipseDBConnection04.png

Then switch to JAR List tab and add the mysql-connector-java. If you don't have it already locally, download from MySQL web page, unzip it and attach the jar file as shown in the picture bellow.

Configure database connection in Eclipse - /images/EclipseDBConnection05.png

Press Ok and jump to the next step.

Step4

Fill all the database details:

  • database name;
  • database URL;
  • username and password. (you can choose to save the password by clicking the Save password checkbox)

Once you have done this, you can test the connection by clicking the Test Connection button. If you see the Ping succeeded! message, press Finish and we are ready to go.

Configure database connection in Eclipse - /images/EclipseDBConnection06.png

Note: if you need the connection all the time you can select "Connect every time the workbench is started".

Step5

To see the database, switch to Database Development perspective and in the Data Source Explorer view you can see the connection and the content to your database.

Configure database connection in Eclipse - /images/EclipseDBConnection07.png

 

References