Techie:Techie Main/Java/Tomcat/Connection Pool: Difference between revisions
No edit summary |
|||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
== Install MySQL drivers == | |||
Copy drivers (e.g. mysql-connector-java-5.0.7-bin.jar) to tomcat's lib directory (e.g. /opt/apache-tomcat-6.0.26/lib/) | |||
== Define pool in <tomcat_install>/conf/context.xml == | == Define pool in <tomcat_install>/conf/context.xml == | ||
| Line 18: | Line 21: | ||
== Create a datasource in the application's web.xml == | == Create a datasource in the application's web.xml == | ||
<pre> | |||
<!-- DataSource resource --> | <!-- DataSource resource --> | ||
<resource-ref> | <resource-ref> | ||
| Line 25: | Line 29: | ||
<res-auth>Container</res-auth> | <res-auth>Container</res-auth> | ||
</resource-ref> | </resource-ref> | ||
</pre> | |||
* Resouce name and res-ref-name must match | * Resouce name and res-ref-name must match | ||
* Connection pool datasource now available using JNDI at 'java:comp/env/jdbc/FantacyDS' | * Connection pool datasource now available using JNDI at 'java:comp/env/jdbc/FantacyDS' | ||
Latest revision as of 10:04, 27 May 2010
Install MySQL drivers
Copy drivers (e.g. mysql-connector-java-5.0.7-bin.jar) to tomcat's lib directory (e.g. /opt/apache-tomcat-6.0.26/lib/)
Define pool in <tomcat_install>/conf/context.xml
<Resource name="jdbc/FantacyDS"
auth="Container"
type="javax.sql.DataSource"
maxActive="10"
maxIdle="3"
maxWait="10000"
username="xxxx"
password="yyyy"
driverClassName="com.mysql.jdbc.Driver"
validationQuery="SELECT 1"
url="jdbc:mysql://localhost/fantacy?autoReconnect=true"/>
- ValidationQuery is required. Without it stale connections cause application errors.
- Not 100% sure if the autoReconnect=true is required, but seems to be suggested on a lot of web pages
Create a datasource in the application's web.xml
<!-- DataSource resource -->
<resource-ref>
<description>FFL DataSource</description>
<res-ref-name>jdbc/FantacyDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
- Resouce name and res-ref-name must match
- Connection pool datasource now available using JNDI at 'java:comp/env/jdbc/FantacyDS'