Вы находитесь на странице: 1из 4

17/11/2011 Using RowSet Objects (The Java Tutorials > JDBC(TM) Database Acces

1/4 docs.oracle.com/javase/tutorial/jdbc/basics/rowset.html
Tail: JDBC(TM) Daabae Acce
Leon: JDBC Baic
Uing RoSe Objec
A JDBC RoSe objec hold abla daa in a a ha make i moe fleible and eaie o e han a el
e.
Oacle ha defined fie RoSe ineface fo ome of he moe popla e of a RoSe, and andad
efeence ae aailable fo hee RoSe ineface. In hi oial o ill lean ho o e hee efeence
implemenaion.
Thee eion of he RoSe ineface and hei implemenaion hae been poided a a conenience fo
pogamme. Pogamme ae fee ie hei on eion of he jaa.l.RoSe ineface, o eend
he implemenaion of he fie RoSe ineface, o o ie hei on implemenaion. Hoee, man
pogamme ill pobabl find ha he andad efeence implemenaion alead fi hei need and ill e
hem a i.
Thi ecion inodce o o he RoSe ineface and he folloing ineface ha eend hi ineface:
JdbcRoSe
CachedRoSe
WebRoSe
JoinRoSe
FileedRoSe
The folloing opic ae coeed:
Wha Can RoSe Objec Do?
Kind of RoSe Objec
Wha Can RoSe Objec Do?
All RoSe objec ae deied fom he RelSe ineface and heefoe hae i capabiliie. Wha make
JDBC RoSe objec pecial i ha he add hee ne capabiliie:
Fncion a JaaBean Componen
Add Scollabili o Updaabili
Fncion a JaaBean Componen
All RoSe objec ae JaaBean componen. Thi mean ha he hae he folloing:
Popeie
JaaBean Noificaion Mechanim
Popeie
17/11/2011 Using RowSet Objects (The Java Tutorials > JDBC(TM) Database Acces
2/4 docs.oracle.com/javase/tutorial/jdbc/basics/rowset.html
All RoSet objec hae popeie. A pope i a field ha ha coeponding gee and ee mehod.
Popeie ae epoed o bilde ool (ch a hoe ha come ih he IDE JDelope and Eclipe) ha
enable o o iall maniplae bean. Fo moe infomaion, ee he Popeie leon in he JaaBean ail.
JavaBeans Notification Mechanism
RoSet objec e he JaaBean een model, in hich egieed componen ae noified hen ceain
een occ. Fo all RoSet objec, hee een igge noificaion:
A co moemen
The pdae, ineion, o deleion of a o
A change o he enie RoSet conen
The noificaion of an een goe o all liene, componen ha hae implemened he RoSetListener
ineface and hae had hemele added o he RoSet objec' li of componen o be noified hen an of
he hee een occ.
A liene cold be a GUI componen ch a a ba gaph. If he ba gaph i acking daa in a RoSet objec,
he liene old an o kno he ne daa ale henee he daa changed. The liene old heefoe
implemen he RoSetListener mehod o define ha i ill do hen a paicla een occ. Then he
liene alo m be added o he RoSet objec' li of liene. The folloing line of code egie he ba
gaph componen bg ih he RoSet objec rs.
rs.addListener(bg);
No bg ill be noified each ime he co moe, a o i changed, o all of rs ge ne daa.
Add Scrollabilit or Updatabilit
Some DBMS do no ppo el e ha can be colled (collable), and ome do no ppo el e
ha can be pdaed (pdaable). If a die fo ha DBMS doe no add he abili o coll o pdae el
e, o can e a RoSet objec o do i. A RoSet objec i collable and pdaable b defal, o b
poplaing a RoSet objec ih he conen of a el e, o can effeciel make he el e collable
and pdaable.
Kinds of RowSet Objects
A RoSet objec i conideed eihe conneced o diconneced. A conneced RoSet objec e a JDBC
die o make a connecion o a elaional daabae and mainain ha connecion hogho i life pan. A
diconneced RoSet objec make a connecion o a daa oce onl o ead in daa fom a ResultSet
objec o o ie daa back o he daa oce. Afe eading daa fom o iing daa o i daa oce, he
RoSet objec diconnec fom i, h becoming "diconneced." Ding mch of i life pan, a diconneced
RoSet objec ha no connecion o i daa oce and opeae independenl. The ne o ecion ell o
ha being conneced o diconneced mean in em of ha a RoSet objec can do.
Connected RowSet Objects
Onl one of he andad RoSet implemenaion i a conneced RoSet objec: JdbcRoSet. Ala being
conneced o a daabae, a JdbcRoSet objec i mo imila o a ResultSet objec and i ofen ed a a
appe o make an oheie non-collable and ead-onl ResultSet objec collable and pdaable.
17/11/2011 Using RowSet Objects (The Java Tutorials > JDBC(TM) Database Acces
3/4 docs.oracle.com/javase/tutorial/jdbc/basics/rowset.html
As a JavaBeans component, a JdbcRoSet object can be used, Ior example, in a GUI tool to select a JDBC
driver. A JdbcRoSet object can be used this way because it is eIIectively a wrapper Ior the driver that
obtained its connection to the database.
Disconnected RoSet Objects
The other Iour implementations are disconnected RoSet implementations. Disconnected RoSet objects have
all the capabilities oI connected RoSet objects plus they have the additional capabilities available only to
disconnected RoSet objects. For example, not having to maintain a connection to a data source makes
disconnected RoSet objects Iar more lightweight than a JdbcRoSet object or a ResultSet object.
Disconnected RoSet objects are also serializable, and the combination oI being both serializable and
lightweight makes them ideal Ior sending data over a network. They can even be used Ior sending data to thin
clients such as PDAs and mobile phones.
The CachedRoSet interIace deIines the basic capabilities available to all disconnected RoSet objects. The
other three are extensions oI the CachedRoSet interIace, which provide more specialized capabilities. The
Iollowing inIormation shows how they are related:
A CachedRoSet object has all the capabilities oI a JdbcRoSet object plus it can also do the Iollowing:
Obtain a connection to a data source and execute a query
Read the data Irom the resulting ResultSet object and populate itselI with that data
Manipulate data and make changes to data while it is disconnected
Reconnect to the data source to write changes back to it
Check Ior conIlicts with the data source and resolve those conIlicts
A WebRoSet object has all the capabilities oI a CachedRoSet object plus it can also do the Iollowing:
Write itselI as an XML document
Read an XML document that describes a WebRoSet object
A JoinRoSet object has all the capabilities oI a WebRoSet object (and thereIore also those oI a
CachedRoSet object) plus it can also do the Iollowing:
Form the equivalent oI a SQL JOIN without having to connect to a data source
A FilteredRoSet object likewise has all the capabilities oI a WebRoSet object (and thereIore also a
CachedRoSet object) plus it can also do the Iollowing:
Apply Iiltering criteria so that only selected data is visible. This is equivalent to executing a query on a
RoSet object without having to use a query language or connect to a data source.
Probl ems wi th the exampl es? Try Compi l i ng and Runni ng the Exampl es: FAQs.
Compl ai nts? Compl i ments? Suggesti ons? Gi ve us your feedback.
Your use of thi s page and al l the materi al on pages under "The Java Tutori al s" banner i s subj ect to these l egal noti ces.
About Oracl e | Oracl e Technol ogy Network | Terms of Servi ce
Copyri ght 1995, 2011
Oracl e and/or i ts affi l i ates. Al l
ri ghts reserved.
17/11/2011 Using RowSet Objects (The Java Tutorials > JDBC(TM) Database Acces
4/4 docs.oracle.com/javase/tutorial/jdbc/basics/rowset.html
Previous page: Using Transactions
Net page: Using JdbcRoSet Objects