This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
I am using tomcat 5.5. I am trying to connect to sql server 2000 database and I use microsoft sql server 2000 driver for jdbc. I have all the jar files in the driver's lib folder copied to CATALINA_HOME\common\lib folder. I added the following in \config\server.xml
<Context path="/mini" reloadable="true"> <Resource name="jdbc/database_access" auth="Container" type="javax.sql.DataSource" username="anil" password="nacware" driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver" url="jdbc:microsoft:sqlserver://localhost:1433;database=mini" maxActive="8" maxIdle="4"/> </Context> I created a mywebapp.xml file in config\CATALINA\localhost and it's contents are:
1. While using tomcat, please ** do not ** edit server.xml to define your context. Define your context in <your_context>.xml and place it in conf/catalina/<host_name> directory (<host_name> would be localhost in your case).
2. You **need not** define any <resource> elements in your web.xml. All resources shall be defined in <your_context>.xml. The following is a sample context.xml that adds a Oracle jdbc connection pool to your web application.
In the above, docBase refers to the directory where you have stored your web application. Not necessary to define <resource> elements in webapps
3. In #2 above, the resource set up is internal to your web application. If you wish that a particular resource be available to all web applications running on the container, heres how you go about
i. in server.xml, define the <resource> element under the <GlobalNamingResources> element.
ii. In your context.xml, define a resource-link element.
That's it - again no need to add resource elements in your web.xml
Note:: The above snippet configures an Oracle datasource. Tweak it appropriately to suit you needs.