Thursday 14 November 2013

Creating Database Connection in Eclipse DTP

In this post, I will create a database connection in Eclipse to MySQL database.

List of software you need:
  • Eclipse IDE with DTP(Data Tools Platfoem). I am using Eclipse Java EE IDE version Kepler which comes with built in DTP. You can download this from Eclipse download page
  • MySQL Server. You will need to install MySQL server. I have installed MySQL Community Server 5.6. You can download it from MySQL Server Download page. This is a link to give more information about installation of MySQL server - Install and configure MySQL Server
  • MySQL Connection driver for Java. You can download it from this page. This will be a zip or gz compressed file. You have to extract it at any location. This contains a .jar file. I am using mysql-connector-java-5.1.25-bin.jar .


 Step 1  Open Eclipse IDE. For first time you will be asked to create new workspace. After landing on workbench Click On Window Menu -> Open Perspective -> Other -> Database Development -> Click on Ok. You will get Database Development perspective. Right Click on Database Connections in Data Source Explorer. Then click on new.

 Step 2  You will get a window to specify connection profile. Select MySQL and give name to your connection.

 Step 3  You have to specify JDBC driver for your connection. If you have not added MySQL driver, then you have to add it. Click on New Driver Definition (just right of driver drop down with + like sign) button.


On new Driver Definition window select specific driver version from driver templates. I am using MySQL driver version 5.1.
On Jar List tab edit existing jar or add new jar. Select mysql-connector-java jar file and click on ok.
 Step 4 If you have not created any database in MySQL yet, just open MySQL command Line Client. And create database using command create database databasename;.

 Step 5  Provide database name,username and password. You can select Connect when wizard Complete and Connect every time wizard started If you like. You have to provide same database name at the end of connection URL as you have created Database in MySQL server. Click on Test Connection If you see message Ping succeeded then you are good. If any failure message comes you have to handle it.

 Step 6  After clicking on finish you can see your connection under database connection.



1 comment:

  1. Thanks Dinesh, I'll soon add one article to your blog regarding how to connect SQL Server 2008 R2 database remotely in java application.

    ReplyDelete