MVC & ResultSet...

Hi...

Why one should use a Collection object which contains javabean objects (one for each for each database row) over ResultSet object in MVC? What are the advantage on not using ResultSet in MVC at presentation layer?

I hope my question is clear enough.

Cheers.

[288 byte] By [jini4javaa] at [2007-11-27 10:21:49]
# 1

Generally it's undesirable to have a direct connection between your GUI and the database - the GUI will be unresponsive (every update has to communicated with the database), and you can potentially make the DB unresponsive for all other users while you're at it.

The CachedRowSet objects may be a suitable alternative in some circumstances, but generally it's easier to integrate Java beans into your business logic than it is to integrate a CachedRowSet. And so it makes more sense to manipulate beans with the GUI than CachedRowSet objects.

dcmintera at 2007-7-28 17:12:16 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

Absolutely right...

The situation is...i have many database search applications...for them i have implemented MVC with struts. I have tried three alternatives strategies..

JSP page fires url, the controller invokes an action (model/business logic). The model then fires a database query and gets ResultsSet... Now, the alternatives are...

1. The model processes the ResultSet objects and put them into ArrayList of arrays for View page...this is column wise distribution of a table... (weired..i know)

2. The model processes the ResultSet with beans. These bean objects are available through ArrayList object on View page.

3. The model obtains the ResultSet object and send to View page through servlet controller.

I know the second one is standard practice.. but my compeers think than it involves extra processing and give same fuctionality as the third one...

What do you think?

And if it is only a search and display functionality... is it a big deal to pass and iterate ResultSet objects in View JSP pages?

Thanks.

jini4javaa at 2007-7-28 17:12:16 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

> What do you think?

>

> And if it is only a search and display

> functionality... is it a big deal to pass and iterate

> ResultSet objects in View JSP pages?

Depends. It's not intrinsically wrong - any old hack can be justified in the name of expedience; it depends what your requirements are. I'd be inclined to at least use a CachedRowSet so I wasn't blocking the DB during page rendering.

dcmintera at 2007-7-28 17:12:16 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

Yap, I guess you are right. I shall try different approaches and then see which is best.

Thanks indeed.

jini4javaa at 2007-7-28 17:12:16 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...