Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Database connection gives exception

 
Rukmini Nagalla
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

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

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

<resource-ref>
<res-ref-name>jdbc/database_access</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

when I run the login servlet which checks the database for user name and passwords, I get this exception:
root cause:
java.lang.NullPointerException
LoginAction.execute(LoginAction.java:37)

Any help is appereciated.
Thanks
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is LoginAction one of your classes? What is on and around line 37?
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Cheers,
Ram.
 
Rukmini Nagalla
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ram, it worked.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic