Tuesday, July 6, 2010

Configuration to mount MySQL data sources on a standalone tomcat server

There are loads of google searches for $Title.So following steps will guide you ,how to do that with a sample testing web app.

1. Gather requirements :
  • Tomcat 5.5 or above
  • MySQL database server
  • Connector: mysql-connector-java-3.1.7-bin.jar
2. Place the mysql connector in CATALINA_HOME/common/lib

3. Create your own sample web app say "myApp".

4. Then place this XML Context tag entry in server.xml (CATALINA_HOME/conf/server.xml) inside .........



Note that ,the username ,password are your MySQL credentials.

5.Then we have to tell the server container where is our jdbc data source is , when running our web app.So for that we have to enter the following resource ref tag entry in your web.xml.


6. Then you only have to do is make a datasource and get a connection with a MySQL DB in your webapp ,say inside a jsp and call it.Here is the code

/**


*/

THATS IT.SIMPLE............ENJOY J2EE.......!