Você está na página 1de 2

JDBC

PreparedStatement
An object that represents a precompiled SQL statement.
A SQL statement is precompiled and stored in a PreparedStatement object.
This object can then be used to efficiently execute this statement multiple
times.
Note: The setter methods (setShort, setString, and so on) for setting IN
parameter values must specify types that are compatible with the defined
SQL type of the input parameter. For instance, if the IN parameter has SQL
type INTEGER, then the method setInt should be used.
If arbitrary parameter type conversions are required, the
method setObject should be used with a target SQL type.
In the following example of setting a parameter, con represents an active
connection:
PreparedStatement pstmt = con.prepareStatement("UPDATE EMPLOYEES
SET SALARY = ? WHERE ID = ?");
pstmt.setBigDecimal(1, 153833.00)
pstmt.setInt(2, 110592)
CallableStatement
The interface used to execute SQL stored procedures.
The JDBC API provides a stored procedure SQL escape syntax that allows
stored procedures to be called in a standard way for all RDBMSs.
This escape syntax has one form that includes a result parameter and one
that does not. If used, the result parameter must be registered as an OUT
parameter. The other parameters can be used for input, output or both.
Parameters are referred to sequentially, by number, with the first
parameter being 1.
{?= call <procedure-name>[(<arg1>,<arg2>, ...)]}
{call <procedure-name>[(<arg1>,<arg2>, ...)]}

IN parameter values are set using the set methods inherited from
PreparedStatement. The type of all OUT parameters must be registered
prior to executing the stored procedure; their values are retrieved after
execution via the get methods provided here.
A CallableStatement can return one ResultSet object or multiple ResultSet
objects. Multiple ResultSet objects are handled using operations inherited
from Statement.

RowSet
A JDBC RowSet object holds tabular data in a way that makes it more
flexible and easier to use than a result set.
A RowSet object is considered either connected or disconnected.
A connected RowSet object uses a JDBC driver to make a connection to a
relational database and maintains that connection throughout its life span.
A disconnected RowSet object makes a connection to a data source only to
read in data from a ResultSet object or to write data back to the data
source. After reading data from or writing data to its data source,
the RowSet object disconnects from it, thus becoming "disconnected."

Only one of the standard RowSet implementations is a


connected RowSet object: JdbcRowSet.
The other four implementations are
disconnected RowSet implementations.
Disconnected RowSet objects have all the capabilities of
connected RowSet objects plus they have the additional capabilities
available only to disconnected RowSet objects.
A CachedRowSet object has all the capabilities of a JdbcRowSet object plus
it can also do the following:
o Manipulate data and make changes to data while it is disconnected
o Reconnect to the data source to write changes back to it
o Check for conflicts with the data source and resolve those conflicts
A WebRowSet object has all the capabilities of a CachedRowSet object plus
it can also do the following:
o Write itself as an XML document
o Read an XML document that describes a WebRowSet object
A JoinRowSet object has all the capabilities of a WebRowSet object (and
therefore also those of a CachedRowSet object) plus it can also do the
following:
o Form the equivalent of a SQL JOIN without having to connect to a
data source
A FilteredRowSet object likewise has all the capabilities of
a WebRowSet object (and therefore also a CachedRowSet object) plus it
can also do the following:
o Apply filtering criteria so that only selected data is visible. This is
equivalent to executing a query on a RowSet object without having
to use a query language or connect to a data source.

CachedRowSet:

A ResultSet is closed as soon as the Statement itself is closed, or used to


retrieve another ResultSet. Therefore, the pointer that once provided a
handle to the query results is no longer valid, and this is
whereCachedRowSet comes in. Unlike a ResultSet, a CachedRowSet stores
all rows obtained from a query in local memory, which can be extremely
convenient at times.

Você também pode gostar