java2db

Jdbc with Mysql in NetBeans and MyEclipse



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

 

Basic requirements to run the application
Softwares MyEclipse or NetBeans IDE (Download MyEclipse , Download NetBeans )
MySQL (Download MySQL)
java (Download java )
Note :Better to use latest versions
Jar Files mysql-connector-java-(version)-stable-bin.jar
Files .java or .class

 

Java database connectivity  (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 MySQL using 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 Mysql

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 Mysql

Click Add External JARs , select the mysql-connector-java-stable-bin.jar  from the existing location. Click OK

Jdbc with Mysql

 

Project Directory Structure :

Below diagram represents the project directory structure .

 

Jdbc with Mysql Example  :

Copy and save the below code in jdbcTestApp.java file

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

 

Jdbc with MySQL using NetBeans :

Create New Project :

Go to File , select New Project sub menu

From Java select Java Application

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

Add Jar Files :

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

Select mysql-connector-java-stable-bin.jar  for the location where it reside , 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 Mysql Example :

Copy and save the below code in jdbcTestApp.java file

Right click on the project and select Run .




Related Posts :
Call database in Jsp (Access Oracle , MySQL , PostgerSQL ,Db2 from Jsp)
Hibernate error user_sequences doesn’t exist in mysql ( resolved )
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

Comments

  1. kiran says:

    Thanks … its very easy to understand…..

   [will not be published]



^ <