*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "JDBC in Action class...???" Watch "JDBC in Action class...???" New topic
Author

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.
Regards,
Varun Narang.


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

Joined: May 26, 2003
Posts: 30050
    
149

Varun,
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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, 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.


Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBC in Action class...???
 
Similar Threads
Checking page sessions
how can i fire update query in struts?
Db2 driver and Distributed transaction
JDBC, mysql connector/j, face a problem to connect mysql 5.1 and JSE.
how to connect java with oracle rdb