I get NullPointerException while running the following program. This program works perfectly in Tomcat 6.0. Why should it fail in JBOSS? If I use "Class.ForName(...)", I am able to access the database.
I guess you are having a NullpointerException because the datasource is not injected (if not, post the exception stacktrace). Which version of JBoss are you using? Injection in servlets is not supported in JBoss version 4.2.x or prior versions. It's supported starting JBoss 5. See this for an explanation.