Friday 26 October 2012

JDBC (JAVA DATABASE CONNECTIVITY)

JDBC (JAVA DATABASE CONNECTIVITY)

Def of  JDBC : JDBC is an API (Application Programming Interface) that is used to connect to any database.

   
       ---> Java API is responsible for connecting to your applications
       ----> JDBC is responsible for connection and communication between java applications
      -----> JCA (JAVA CONNECTOR ARCHITECTURE) is responsible for ApplicationServer to database

    JDBC PROVIDER(OR) RESOURCE : To create a jdbc provider we need

    
This is one way of creating JDBC PROVIDER

   ----> Vendor details will be present in JDBC providers (Any Vendor MYSQL,ORACLE)



1) Adapter : It is a jar file responsible for communication between java application and database

2) Implementation class name

goto Admin Console page


Resources----> JDBC Providers -----> New




Step1: Select Database type -----> Choose your database type (MYSQL,ORACLE,DB2)

Step2: Select JDBC Provider type

Step3: Select Implementation type

Step4: Apply

Step5: Now create required DataSources

Goto Resources----> JDBC Providers ---> JDBC Provider ----> DataSources ----> New

---> To create any JDBC we required one database we have taken MYSQL

---> To goto MYSQL firstly we have to install MYSQL software in ur system or laptop



MYSQL: 

Enter Password : MYSQL


MYSQL> Create database testdb


MYSQL> use testdb


Create a table

To check fields of table


MYSQL> describe testdbl


MYSQL> insert into testtbl values ('255','','',);


Second way of creating JDBC PROVIDER

---> To connect to database we need JAR file

        mysql-connector-java-5.1.13bin.jar

Steps for creating JDBC PROVIDER :




Step1:  Select scope in JDBC Provider

Step2:  Select Node and Click New

Step3: Database Type ----> User Defined

Step4: Implementation Class Name : This must be paste from MYSQL notepad provided by Vendor


Step5: Name : MYSQLRESOURCE ---> Next

Classpath : D:\temp\mysql-connector-java-5.1.13bin.jar ----> finish ----> Save

Step6 : Create DataSource

Select Scope ----> New ---> JDBCProvider Name


DataSource Name-----> testDBDSN

JNDI Name----> Test JNDI (jdbc/mysqldsref---->next---->sqlprovider---->next--->next---->finish

Step7:  Goto Custom Properties

we have to set 5 properties
1) DBNAME
2) SERVER NAME
3) USER NAME
4) PASSWORD
5) PORT NUMBER

Search for dbname---->testdb
                ServerName---->localhost
                PortNumber---->3306
                User---->root
              Password---->MYSQL

Click save---> next--->Test Connection

Start the Server

C:\IBM\WEBSPHERE\APPSERVER> StartServer.bat

----> Deploy sample application


goto ApplicationServer--->Install New Application ----> Browse ----> next----> next

To see the application


http://localhost:9080/mysqltestwebproject/MYSQLTestServlet



0 comments:

Post a Comment