Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / January 2008

Tip: Looking for answers? Try searching our database.

Using ResultSet in a TableModel?

Thread view: 
mdR - 28 Jan 2008 14:14 GMT
in all the example programs i've looked at and reading i've done on
extending AbstractTableModel for use in a JTable... the data returned
in a ResultSet using JDBC with an SQL query is read and placed in a
container object; such as Vector or the newer ArrayList.  I have a
couple of questions...

Why is this done?  Can't you simply keep the ResultSet and work with
that directly in the getValue and setValue methods?

and secondly,  (not sure if i'm explaining this adequately) so far i
have been using traditional(?) methods: load the JDBC driver, create
the connection, retrieve the data with a ResultSet query, then add the
TableModel to my JTable.  Should i instead look at using a RowSet
class, such as JDBCRowSet for data management?  i'm a little confused
on when a RowSet object is used in a GUI.

tia for your reply.
-mark
Lew - 28 Jan 2008 15:26 GMT
> in all the example programs i've [sic] looked at and reading i've done on
> extending AbstractTableModel for use in a JTable... the data returned
> in a ResultSet using JDBC with an SQL query is read and placed in a
> container object; such as Vector or the newer ArrayList.

Yah, newer.  ArrayList was introduced in 1998, just about when most folks were
first learning of Java's existence.

> I have a couple of questions...
>
> Why is this done?  Can't you simply keep the ResultSet and work with
> that directly in the getValue and setValue methods?

Yes, but that requires keeping the connection open, and connections tend to be
both scarce and expensive.

Copying the data into a Collection <? extends Entity> lets one close the
ResultSet and owning connection quickly.

> and secondly,  (not sure if i'm explaining this adequately) so far i
> have been using traditional(?) methods: load the JDBC driver, create
> the connection, retrieve the data with a ResultSet query, then add the
> TableModel to my JTable.

You're only loading the JDBC driver class once, right?

> Should i [sic] instead look at using a RowSet class, such as JDBCRowSet for data management?
> i'm a little confused on when a RowSet object is used in a GUI.

Did you look at using RowSet?  Why wouldn't you look at it?

When you read the Javadocs
<http://java.sun.com/javase/6/docs/api/javax/sql/RowSet.html>
did anything catch your eye?

I'll tell you what caught my eye:
> A rowset may also make a connection with a data source, get data from it,
> and then close the connection. Such a rowset is called a disconnected rowset.

What else caught my eye was:
> The interface that adds support to the JDBC API for the JavaBeans(TM) component model.
> A rowset, which can be used as a JavaBeans component in a visual Bean development
> environment, can be created and configured at design time and executed at run time.

Note the phrase, "visual Bean development environment".  That's not precisely
what you asked for, but it shows that it's consistent with what you asked for.

In fact, the design philosophy of JavaBeans is purposefully GUI-friendly.
More importantly, it's a component model.  That means that RowSet should play
very well with good architectures GUI and otherwise.

I'd not only consider, but actually use RowSets.  Especially if they live up
to the Javadocs' promise that, "Rowsets [sic] are easy to use."

Signature

Lew

mdR - 29 Jan 2008 14:41 GMT
> Yah, newer.  ArrayList was introduced in 1998, just about when most folks were
> first learning of Java's existence.

ha :)

> > Why is this done?  Can't you simply keep the ResultSet and work with
> > that directly in the getValue and setValue methods?
[quoted text clipped - 4 lines]
> Copying the data into a Collection <? extends Entity> lets one close the
> ResultSet and owning connection quickly.

i get it...

> You're only loading the JDBC driver class once, right?

yup

> Did you look at using RowSet?  Why wouldn't you look at it?
>
[quoted text clipped - 16 lines]
> More importantly, it's a component model.  That means that RowSet should play
> very well with good architectures GUI and otherwise.

thanks... i think i have a much better understanding.
so i could work directly with the rowset object getting and setting
data, then save back to the db if desired.
what if the db was extremely large?  wouldn't you then use JDBCRowSet
and maintain the connection?

-mark


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.