The moose likes Struts and the fly likes JDBC in Action class...??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "JDBC in Action class...???" Watch "JDBC in Action class...???" New topic

JDBC in Action class...???

Varun Narang
Ranch Hand

Joined: Nov 19, 2004
Posts: 30
Hello every one,
I have a query. Can anyone tell me if it's a good idea to put JDBC code in the Action class or it'll be better to put it in a different POJ class.
Any answers will be highly appriciated.
Varun Narang.

Your computer system is like AC, it's of no use when you open Windows ;)
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33107

It's better not to have JDBC in the Action class for the same reason it is better not to have it in a Servlet. In general, you want to keep your web layer and database layer in different classes. This makes it easier to change them independently of each other.

[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
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I agree with Jeanne. One of the main reasons for using Struts is to assist you in following the Model/View/Controller (MVC) pattern. An Action class belongs in the controller space, and classes that are tied to the Database generally belong in the Model space. You want to separate controller functions from model functions.

Consultant, Sima Solutions
I agree. Here's the link:
subject: JDBC in Action class...???
It's not a secret anymore!