Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlet calling a database access file

 
nash avin
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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
AS
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it is better if both move to the separate class. Then your database code is all together, which is clearer.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic