File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

database access through servlet....

arvind doraiswamy

Joined: Jun 19, 2004
Posts: 11
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?
David O'Meara

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.

arvind doraiswamy

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..
I agree. Here's the link:
subject: database access through servlet....
It's not a secret anymore!