Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Best practice for dealing with Recordsets, JDBC and JSP?

843836Mar 30 2005 — edited Mar 31 2005
I've spent the last three years developing web apps using JSP, Struts and Kodo JDO for persistence. All of the content for the apps was created as Java objects using model classes and saved to an Oracle db. Thus, data retrieved from the db was as instances of the model classes and then put into Struts form beans, etc.

I changed jobs last month and am now having to use Servlets with JDBC to retrieve records from db tables and returning it into Recordsets. Oh, and I can't use Struts in my JSPs either. I'm beginning to think that I had it easy at my previous job but maybe that's just because I was used to it.

So here are my problems/questions:

I have two tables with a one to many relationship that I need to retrieve data from, show in a jsp and be able to update eventually.

So here's what I am doing:
a) In a servlet, I use a SQL statement to join the tables and retrieve the results into a Recordset.
b) I created a class with a bunch of String attributes to copy the Recordset data into, one Recordset row per each instance of the bean and then close the Recordset
c) I then add the beans to an ArrayList and save the ArrayList into the session.
d) Then, in the JSP, I retrieve the ArrayList from the session and iterate over each bean instance, printing the data out to the jsp. There are some logic statements to determine when not to print redundant data caused by the one to many join.
e) I have not written the code to update the data yet but was planning on having separate jsps for updating the (one) table and the (many) table.

Would most of you do something similar? Would you use one SQL statement to retrieve all of the data for display and use logic to avoid printing the redundant part of the data? Or would you have used separate SQL queries, one for each table? Would you have saved the results into something other than an instance of a bean class that represents one record in the RecordSet? Would you have had a bean class with attributes other than Strings - like had a collection attribute to hold the results from the "many" table? The way that I am doing everything just seems so cumbersome and difficult compared to using Struts and JDO before.

Your help/opinion will be greatly appreciated!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 28 2005
Added on Mar 30 2005
2 comments
369 views