Databases Reference
In-Depth Information
The following examples show the benefit of using the getMetadata()
method over using the getColumns() method.
Example A: Using the getColumns() Method
A potentially complex query is prepared and executed, result descrip-
tion information is formulated, the driver retrieves the result rows, and
the application fetches the result. This method results in increased CPU
use and network communication.
ResultSet WSrc = WSc.getColumns (... "UnknownTable" ...);
// getColumns() will generate a query to
// the system catalogs and possibly a join
// that must be prepared, executed, and produce
// a result set
...
WSrc.next();
string Cname = getString(4);
...
// user must retrieve N rows from the database
// N = # result columns of UnknownTable
// result column information has now been obtained
Example B: Using the getMetadata() Method
A simple query that retrieves result set information is prepared, but the
query is not executed and the driver does not retrieve result rows. Only
information about the result set is retrieved (the same information
retrieved by getColumns() in Example A).
// prepare dummy query
PreparedStatement WSps = WSc.prepareStatement
("SELECT * FROM UnknownTable WHERE 1 = 0");
// query is not executed on the database - only prepared
ResultSetMetaData WSsmd=WSps.getMetaData();
Search WWH ::




Custom Search