wood burning stoves 2.0*
The moose likes Servlets and the fly likes database access through servlet.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "database access through servlet...." Watch "database access through servlet...." New topic
Author

database access through servlet....

arvind doraiswamy
Greenhorn

Joined: Jun 19, 2004
Posts: 11
Hi,
Sort of strange this...I've written some java code which accesses a mysql database and it works absolutely perfect.However when i put the same code into a servlet the servlet throws a classnotfound exception.Is there any specific reason for this because as far as i can gather if it runs normally as independent java code without throwing any exceptions it should run in a servlet also .Do let me know if im missing out anything here?
Thanks
Arvind
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Application servers ignore the classpath. There is an important reason why they have to, but the short answer is that you probably need to place the mysql driver jar in the web-inf/lib directory to get it to work.

App servers are designed to run several applications at the same time and pretend that each is the only one running - ie it should minimise conflicts and crossovers between applications. To assist this, some ClassLoader tricks are used to make sure App A can't see App B or related classes. If they all ran off the class path this wouldn't work, so applciation servers pretend to create a separate classpath for each application running in the application server.

Dave
arvind doraiswamy
Greenhorn

Joined: Jun 19, 2004
Posts: 11
Hi david,
Thnx man...ill try that...though i didnt get the reason ...sorry...guess im just real new to java..
Arvind
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: database access through servlet....