I\'m creating a series of webservices for my application and i have the need to access a different database based on the serviceCode that is passed as a parameter in the web
Define your own Resource. See the Tomcat documentation. You provide an implementation of javax.naming.spi.ObjectFactory. Have it return an appropriate implementation of Context such that looking it up via some name returns a DB connection to that name. In my case the required entry in context.xml looked like this:
<Resource
name="ldap/Context" // your name, probably something like jdbc/dynamic
auth="Container"
type="javax.naming.ldap.LdapContext"
factory="com.xxxx.ldap.LdapContextFactory"
// your initialization params here, if any
>