how can we use jdbc connection pooling for mysql database?

RamanaRamana Hyderabad

I want perfect example for creating connection, setting max connections,closing connections

Comments

  • Create new resource:
    %document_root%/META-INF/context.xml

    <Resource name="jdbc/appname" auth="Container"
    type="javax.sql.DataSource" maxActive="100" 
    maxIdle="30" maxWait="10000"
    username="username" 
    password="password"
    driverClassName="jdbc.driver.name"
    url="jdbc:protocol://hostname:port/dbname"/>
    

    web.xml:

    <resource-ref>
    DB Connection
    <res-ref-name>jdbc/appname</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>
    

    Java:

    InitialContext initContext= new InitialContext();
    DataSource ds = (DataSource) initContext.lookup("java:comp/env/jdbc/dbconnect");
    Connection conn = ds.getConnection();
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion