executeAndGuessTableName and executeAndGuessTableNameAndPrimaryKeys Setting Table and Primary Key Information Using the MetaData Interface Setting the Write Table

Using RowSets with WebLogic Server 6-11 ■ Section 6.6.2, Setting Table and Primary Key Information Using the MetaData Interface ■ Section 6.6.3, Setting the Write Table

6.6.1 executeAndGuessTableName and executeAndGuessTableNameAndPrimaryKeys

When populating a rowset with an SQL query, you typically use the execute method to run the query and read the data. The WLCachedRowSet implementation provides the executeAndGuessTableName and executeAndGuessTableNameAndPrimaryKeys methods that extend the execute method to also determine the associated table metadata. The executeAndGuessTableName method parses the associated SQL and sets the table name for all columns as the first word following the SQL keyword FROM. The executeAndGuessTableNameAndPrimaryKeys method parses the SQL command to read the table name. It then uses the java.sql.DatabaseMetaData to determine the tables primary keys.

6.6.2 Setting Table and Primary Key Information Using the MetaData Interface

You can also choose to manually set the table and primary key information using the WLRowSetMetaData interface. WLRowSetMetaData metaData = WLRowSetMetaData rowSet.getMetaData; Sets one table name for all columns metaData.setTableNameemployees; or metaData.setTableNamee_id, employees; metaData.setTableNamee_name, employees; You can also use the WLRowSetMetaData interface to identify primary key columns. metaData.setPrimaryKeyColumne_id, true; See the Javadoc for weblogic.jdbc.rowset.WLRowSetMetaData for more details.

6.6.3 Setting the Write Table

The WLRowSetMetaData interface includes the setWriteTableName method to indicate the only table that should be updated or deleted. This is typically used when a rowset is populated with a join from multiple tables, but the rowset should only update one table. Any column that is not from the write table is marked as read-only. For instance, a rowset might include a join of orders and customers. The write table could be set to orders. If deleteRow were called, it would delete the order row, but not delete the customer row. Note: These methods rely on support in the DBMS or JDBC driver. They do not work with all DBMSs or all JDBC drivers. 6-12 Oracle Fusion Middleware Programming JDBC for Oracle WebLogic Server

6.7 RowSets and Transactions