java2db

Jdbc with DB2 in NetBeans and MyEclipse



JDBC application programming interface is one of the best and easiest ways to interact with the database.See below , Jdbc with DB2  using NetBeans and MyEclipse in a simple and detailed way.

 

 

Basic requirements
Softwares MyEclipse or NetBeans IDE (Download MyEclipse , Download NetBeans )
DB2 (Download DB2)
java (Download java )
Note :Better to use latest versions
Jar Files db2jcc.jar  ,  db2jcc_license_cu.jar  ,  db2jcc_license_cisuz.jar
Files .java or .class

 

JDBC is a specification from Sun Microsystems and provides a standard abstraction in the form APIs of protocols for java applications to communicate with different relational databases . Below example , used type-4 driver to connect with the database.

 

Jdbc with DB2 in MyEclipse :

Create New Project :

Go to File , New and select Java Project

 

Enter valid name of the project in the popup window , click Finish button.

Jdbc with DB2 in NetBeans and MyEclipse

So the new project created in the top-left corner of the MyEclipse IDE .

 

Add Jar Files :

Right click on the project and select Build Path , Configure Build Path sub menu

Jdbc with DB2 in NetBeans and MyEclipse

Click Add External JARs , select  db2jcc.jar  ,  db2jcc_license_cu.jar  and  db2jcc_license_cisuz.jar  from the existing location. Click OK

Jdbc with DB2 in NetBeans and MyEclipse

 

Project Directory Structure :

This diagram represents the project directory structure .

 

Jdbc with DB2  example code:

Copy and save the below code in jdbcTestApp.java file

From the url :

localhost : represents the local machine (127.0.0.1) IP , if the database is in remote machine , specify the IP  (ex: 10.180.3.40) .

50008 : Is the port number that can hear by the DB2.

DB2DT : Is the darabase name.

 

To run the application , right click on the project and select Run As -> Java Application.

 

Jdbc with DB2 using NetBeans :

Create New Project :

Go to File , select New Project sub menu

select Java , Java Application

Enter appropriate project name in the Project Name box. click Finish.

Add Jar Files :

Expand project , Right click on Libraries , select Add JAR/Folder

Select db2jcc.jar  ,  db2jcc_license_cu.jar  ,  db2jcc_license_cisuz.jar  for the location where it reside  and finally click open .

Project Directory Structure :

See the project directory structure in the top-left side of the NetBeans IDE. It should be like below.

Jdbc with DB2  example code :

Copy and save the below code in jdbcTestApp.java file

From the url :

localhost : represents the local machine (127.0.0.1) IP , if the database is in remote machine , specify the IP  (ex: 10.180.3.40) .

50008 : Is the port number that can be hear by the DB2 .

DB2DT : Is the darabase name .

 

Right click on the project and select Run .

 




Related Posts :
Jsp , Servlet and JDBC login application example in NetBeans
Jsp,Servlet and JDBC integration example in Eclipse
Connect DB2 with Hibernate 4 in MyEclipse,NetBeans,RAD
Connect PostgreSQL with Hibernate 4 in Myeclipse,NetBeans,RAD
Connect MySQL with Hibernate 4 in NetBeans,MyEclipse,RAD
Connect oracle with hibernate in MyEclipse, NetBeans, RAD
Jdbc with Mysql in NetBeans and MyEclipse
Jdbc with PostgreSQL using MyEclipse and NetBeans
   [will not be published]



^ <