Wednesday 27 November 2013

Javax.sql.DataSource implementation

Javax.Sql.DatSource implementation

Hello friends ..today i am going to demonstrate you implementation of javax.sql.DataSource. Apache do have its own connection pooling implementation called as BasicDataSource.you can use this implementation for defining  DataSource Configuration & inject it into SessionFactory .

in this example i am demonstarting the implementation of DataSource which is commonly used for Connection Pooling purpose.it reduces number of active connections required .every time Application gets deployed into application server ,it is the responsibility of container to provide Connection  whenever required . well i am referring this concept as caching.simply because whenever you need connection object ,container have it ,what it is doing is simply giving you copy of connection object back.

DataSource implementation is Container Manged Object.in this example i am defining Connection object into server.xml which will be placed in META-INF.


Pojo Class
package org.demo;

public class Customer
{
   
    private int id;
    private String name;
    private String address;
   
   
    public int getId()
    {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }
   
   

}

Context.xml file
<?xml version="1.0" encoding="UTF-8"?>

<context>

<Resource name="jdbc/Mydb" auth="Container" type="javax.sql.DataSource"
               maxActive="50" maxIdle="30" maxWait="10000"
               username="app" password="app"
               driverClassName="org.apache.derby.jdbc.ClientDriver "
               url="jdbc:derby://localhost:1527/sample"/>
   </context>




web.xml file 
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>Jndiq1</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
 
  <resource-ref>
    <description>Apache derby DataSource Example</description>
    <res-ref-name>jdbc/Mydb</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>
</web-app>


hope you have understand the concept
thanks
for any query ping me on pathak.nisarg@yahoo.com

No comments:

Post a Comment

Spring Boot SSL configuration -Tomcat Server

Hi Friends hope you all are doing well. Today I am going to demonstrate about how to configure SSL in Spring boot web Application. Need o...