 |
|
 |
|
Next: Special Characters into database
|
| Author |
Message |
External

Since: Dec 11, 2007 Posts: 14
|
(Msg. 1) Posted: Mon Jan 28, 2008 6:14 am
Post subject: Using ResultSet in a TableModel? Archived from groups: comp>lang>java>databases (more info?)
|
|
|
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 >> Stay informed about: Using ResultSet in a TableModel? |
|
| Back to top |
|
 |  |
External

Since: Aug 30, 2007 Posts: 57
|
(Msg. 2) Posted: Mon Jan 28, 2008 10:26 am
Post subject: Re: Using ResultSet in a TableModel? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
mdR wrote:
> 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."
--
Lew >> Stay informed about: Using ResultSet in a TableModel? |
|
| Back to top |
|
 |  |
External

Since: Dec 11, 2007 Posts: 14
|
(Msg. 3) Posted: Tue Jan 29, 2008 6:41 am
Post subject: Re: Using ResultSet in a TableModel? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
> 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?
>
> 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.
>
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?
>
> 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.
>
> 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.
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 >> Stay informed about: Using ResultSet in a TableModel? |
|
| Back to top |
|
 |  |
|
You can post new topics in this forum You can reply to topics in this forum You can edit your posts in this forum You can delete your posts in this forum You can vote in polls in this forum
|
|
|
|
 |
|
|