Hi, I have concerns about using sql query in action classes and jsp pages since I considered querying as model layer process. If I use queries in the controller or view, does it violate mvc or it should be ok for read only access and can boost performance? Any comments are appreciated.
Make sure is thread safe and second thing why put all the data access login at the controller level ? The best practise is segegrade them into the session bean.
I normally only use controllers (Actions) as mere traffic cops, without any real business logic in them. They delegate to other objects, and that could include some form of Data Access Object. The DAO would do the database access for you, returning its results to your controller layer, which in turn answers the results to your view (through normal Java return mechanisms).
If you code your queries into your controller layer, then you're creating a problem for yourself when you want to use those same queries in other objects.
As a side note, consider creating Query objects, DAOs etc and using them in your model layer where possible. You end up with some cool reusable classes that can be used by anything, not just controllers.
Thanks for all your replies. It seems I should stick to the best practices. :)