aspose file tools*
The moose likes Servlets and the fly likes Database connection gives exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Database connection gives exception" Watch "Database connection gives exception" New topic

Database connection gives exception

Rukmini Nagalla

Joined: Apr 29, 2005
Posts: 11
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="" url="jdbc:microsoft:sqlserver://localhost:1433;database=mini"
maxActive="8" maxIdle="4"/>
I created a mywebapp.xml file in config\CATALINA\localhost and it's contents are:

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/ora">
<ResourceLink name="jdbc/database_access" global="jdbc/database_access" type="javax.sql.DataSource" />

I have added the following in /WEB-INF/webapp.xml :


when I run the login servlet which checks the database for user name and passwords, I get this exception:
root cause:

Any help is appereciated.
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

Is LoginAction one of your classes? What is on and around line 37?
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

I would suggest you do the following.

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.

Rukmini Nagalla

Joined: Apr 29, 2005
Posts: 11
Thanks Ram, it worked.
I agree. Here's the link:
subject: Database connection gives exception