JDBC Driver - ResultSetMetadata

On this page

ResultSet.getMetaData() returns java.sql.ResultSetMetaData. Most getters take a one-based result column index. The metadata describes the projection, including expressions and aliases. For catalog tables and columns, use DatabaseMetaData.

Column properties

Method Driver 3.1 behavior
getColumnCount() Number of projected columns.
getColumnLabel(index) Label to use with the result set’s named getters, commonly the SQL alias.
getColumnName(index) Column name from the server’s metadata.
getSchemaName(index), getTableName(index) Namespace and entity name when supplied by the server.
getCatalogName(index) The driver returns an empty catalog name for query columns.
getColumnType(index) java.sql.Types code mapped from the Prism type.
getColumnTypeName(index) Prism type name. For an array, the returned name describes the element type while getColumnType returns Types.ARRAY.
getColumnClassName(index) An empty string for ordinary query metadata. Use the conversion table to choose a getter.
getColumnDisplaySize(index), getPrecision(index) Length and precision from the server’s column metadata.
getScale(index) Returns the driver’s placeholder scale 1 for query results. Do not use it to infer a declared decimal scale.
isNullable(index) Returns columnNullable or columnNoNulls based on the server metadata.
isCaseSensitive(index) Returns true in query metadata.
isAutoIncrement(index), isSearchable(index), isCurrency(index), isSigned(index) Return false as driver defaults.
isReadOnly(index), isWritable(index), isDefinitelyWritable(index) Return false as driver defaults. Actual JDBC result sets are read-only.
isWrapperFor(type), unwrap(type) Check or obtain the compatible metadata implementation.

Example: inspect a projected column

First run the Statement setup example.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;

public class InspectColumns {
    public static void main(String[] args) throws Exception {
        String url = args.length == 0 ? "jdbc:polypheny://localhost:20590" : args[0];
        try (Connection connection = DriverManager.getConnection(url, "pa", "");
             Statement statement = connection.createStatement();
             ResultSet rows = statement.executeQuery(
                 "SELECT id, title AS task_title FROM public.jdbc_docs_tasks")) {
            ResultSetMetaData columns = rows.getMetaData();
            for (int i = 1; i <= columns.getColumnCount(); i++) {
                System.out.printf("%s (%s)%n", columns.getColumnLabel(i), columns.getColumnTypeName(i));
            }
        }
    }
}
© Polypheny GmbH. All Rights Reserved.