skip to main content
Developing JDBC Applications : ResultSet Metadata Support
 

ResultSet Metadata Support

If your application requires table name information, the JDBC Client can return table name information in ResultSet metadata for Select statements. By setting the ResultSetMetaDataOptions property to 1, the JDBC Client performs additional processing to determine the correct table name for each column in the result set when the ResultSetMetaData.getTableName() method is called. Otherwise, the getTableName() method may return an empty string for each column in the result set.
The table name information that is returned by the JDBC Client depends on whether the column in a result set maps to a column in a table in the database. For each column in a result set that maps to a column in a table in the database, the JDBC Client returns the table name associated with that column. For columns in a result set that do not map to a column in a table (for example, aggregates and literals), the JDBC Client returns an empty string.
The Select statements for which ResultSet metadata is returned may contain aliases, joins, and fully qualified names. The following queries are examples of Select statements for which the ResultSetMetaData.getTableName() method returns the correct table name for columns in the Select list:
SELECT id, name FROM Employee
SELECT E.id, E.name FROM Employee E
SELECT E.id, E.name AS EmployeeName FROM Employee E
SELECT E.id, E.name, I.location, I.phone FROM Employee E, EmployeeInfo I
WHERE E.id = I.id
SELECT id, name, location, phone FROM Employee, EmployeeInfo
WHERE id = empId
SELECT Employee.id, Employee.name, EmployeeInfo.location, EmployeeInfo.phone
FROM Employee, EmployeeInfo
WHERE Employee.id = EmployeeInfo.empId
The table name returned by the JDBC Client for generated columns is an empty string. The following query is an example of a Select statement that returns a result set that contains a generated column (the column named "upper").
SELECT E.id, E.name as EmployeeName, {fn UCASE(E.name)}
AS upper FROM Employee E
The JDBC Client also can return schema name and catalog name information when the ResultSetMetaData.getSchemaName() and ResultSetMetaData.getCatalogName() methods are called if the driver can determine that information. For example, for the following statement, the JDBC Client returns "test" for the catalog name, "test1" for the schema name, and "foo" for the table name:
SELECT * FROM test.test1.foo
The additional processing required to return table name, schema name, and catalog name information is only performed if the ResultSetMetaData.getTableName(), ResultSetMetaData.getSchemaName(), or ResultSetMetaData.getCatalogName() methods are called.