File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes servlet calling a database access file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet calling a database access file" Watch "servlet calling a database access file" New topic

servlet calling a database access file

nash avin
Ranch Hand

Joined: Nov 13, 2003
Posts: 96
I have a servlet in which all the code for database is present.This is a bad idea i am told,so I was suggested that I move all the database connection code to another class and make the server call that class(make an instance of the class).
Now the servlet class I have has the init() method and doPost() method.In the init() method I have

In the doPost() method I have the following code

My question now is,Do I have to just put what ever code is in the doPost() method into a separate .class file.Or do I have to put both the contents of doPost() and init() methods into another .class file.
Kindly let me know what could be a possible solution.Hope that I have told my problem properly.
Hoping to hear from you soon.
Thanks in advance
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33117

I think it is better if both move to the separate class. Then your database code is all together, which is clearer.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: servlet calling a database access file
It's not a secret anymore!