Java Reference
In-Depth Information
ResultSetMetaData method getColumnName (p. 1073) obtains a ResultSet column's name.
TableModel method getRowCount (p. 1073) returns the number of rows in the model's ResultSet .
TableModel method getValueAt (p. 1073) returns the Object at a particular row and column of
the model's underlying ResultSet .
ResultSet method absolute (p. 1073) positions the ResultSet cursor at a specific row.
AbstractTableModel method fireTableStructureChanged (p. 1074) notifies any JTable using a
particular TableModel object as its model that the data in the model has changed.
Section 24.7 RowSet Interface
• Interface RowSet (p. 1080) configures a database connection and executes a query automatically.
• A connected RowSet (p. 1080) remains connected to the database while the object is in use. A
disconnected RowSet (p. 1080) connects, executes a query, then closes the connection.
JdbcRowSet (p. 1080) (a connected RowSet ) wraps a ResultSet object and allows you to scroll and
update its rows. Unlike a ResultSet object, a JdbcRowSet is scrollable and updatable by default.
CachedRowSet (p. 1080), a disconnected RowSet , caches a ResultSet 's data in memory. A
CachedRowSet is scrollable and updatable. A CachedRowSet is also serializable.
• Class RowSetProvider (package javax.sql.rowset ; p. 1080) provides static method newFacto-
ry which returns an object that implements interface RowSetFactory (package javax.sql.row-
set ) that can be used to create various types of RowSet s.
RowSetFactory (p. 1080) method createJdbcRowSet returns a JdbcRowSet object.
JdbcRowSet method setUrl specifies the database URL.
JdbcRowSet method setUsername specifies the username.
JdbcRowSet method setPassword specifies the password.
JdbcRowSet method setCommand specifies the SQL query that will be used to populate a RowSet .
JdbcRowSet method execute executes the SQL query. Method execute performs establishes a
Connection to the database, prepares the query Statement , executes the query and stores the Re-
sultSet returned by query. The Connection , Statement and ResultSet are encapsulated in the
JdbcRowSet object.
Section 24.8 PreparedStatement s
PreparedStatement s (p. 1082) are compiled, so they execute more efficiently than Statement s.
PreparedStatement s can have parameters, so the same query can execute with different arguments.
• A parameter is specified with a question mark ( ? ) in the SQL statement. Before executing a Pre-
paredStatement , you must use PreparedStatement 's set methods to specify the arguments.
PreparedStatement method setString 's (p. 1082) first argument represents the parameter num-
ber being set and the second argument is that parameter's value.
• Parameter numbers are counted from 1, starting with the first question mark ( ? ).
•Method setString automatically escapes String parameter values as necessary.
• Interface PreparedStatement provides set methods for each supported SQL type.
Section 24.9 Stored Procedures
• JDBC enables programs to invoke stored procedures (p. 1098) using CallableStatement
(p. 1098) objects.
CallableStatement can specify input parameters. CallableStatement can specify output param-
eters (p. 1098) in which a stored procedure can place return values.
Search WWH ::




Custom Search