Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC connection pooling

 
A knibbs
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all I am wondering if someone might happen to have a link to a sample application using best practices for a JDBC connection pool in struts.

thanks in advance for your time.
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Struts itself has connection pooling support using DBCP(Database Connection Pooling). commons-pool-1.2.jar which comes with Sturts download.

For configuring DBCP with sturts,

URL

Example:

<data-sources>
<data-source type="org.apache.commons.dbcp.BasicDataSource" key="mysql">
<set-property property="driverClassName" value="com.mysql.jdbc.Driver"></set-property>
<set-property property="url" value="jdbc:mysql://testServer/test"></set-property>
<set-property property="username" value="test"></set-property>
<set-property property="password" value="test"></set-property>
<set-property property= "maxCount" value= "100"></set-property>
<set-property property= "minCount" value= "0"></set-property>
</data-source>
</data-sources>
 
A knibbs
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the data source defined and am able to make connections. I guess what I am asking moreso is what is the best manner to cget the connection as well as relinquish them. The thought right now is to pass a connection as a parameter and close it using connection.close. Would that be sufficient ?

thanks again in advance.
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. use DataSource to get connection.

2. close connection when ever you done with it.

This is optimized way of using JDBC Connection.

hth,
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry for mutiple posts.

URL I found which is very useful for JDBC optomization.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic