cancel
Showing results for 
Search instead for 
Did you mean: 

HANA JDBC: potential metadata bug

Former Member
0 Kudos

When using the HANA JDBC I am making use of the drivers metadata.

I use getMetaData() on a new connection and then try to use getPrimaryKeys() on the connections metadata.I am expecting a resultSet of primary keys when the table name is used as the third parameter to getPrimaryKeys();

However the actual result is that the result set is empty.

Below is a github gist where I show creating the tables and then attempting to access the primary key information from meta data.

Any information would be helpful, thanks in advance.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Still occurring on:

Database product version: 1.00.62.380773

JDBC driver version: 1.00.60.Build 0379371-1510

lbreddemann
Active Contributor
0 Kudos

Hi Carl,

first of all: THIS is exactly the right way to post problems/questions!

Show us what you're doing, show us the code!

With your demo code you provided it was super easy to find the problem:

You use

if (conn.getMetaData().getPrimaryKeys(null, null, "test.a").next() == true)

to get the result for table TEST.A.

The thing with identifiers (table/view names, column names, etc.) in SAP HANA is that unless you enclose them into double quotation marks (" ") SAP HANA will transpose them into upper case characters before further processing.

Therefore, you need to look for TEST.A instead of test.a.

Changing your code to

if (conn.getMetaData().getPrimaryKeys(null, null, "TEST.A").next() == true)

should fix the issue.

- Lars

Former Member
0 Kudos

Hi Lars,

Thank you for your reply.

It turns out that the fully qualified table name 'TEST.A' did not work.

It should be

if (conn.getMetaData().getPrimaryKeys(null, "TEST", "B").next() == true

lbreddemann
Active Contributor
0 Kudos

Hi Carl,

yeah - my bad!

Reading the JDBC docs would have helped here...

"

  • getPrimaryKeys

    ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLExceptionRetrieves a description of the given table's primary key columns. They are ordered by COLUMN_NAME.

    Each primary key column description has the following columns:

    1. TABLE_CAT String => table catalog (may be null)
    2. TABLE_SCHEM String => table schema (may be null)
    3. TABLE_NAME String => table name
    4. COLUMN_NAME String => column name
    5. KEY_SEQ short => sequence number within primary key( a value of 1 represents the first column of the primary key, a value of 2 would represent the second column within the primary key).
    6. PK_NAME String => primary key name (may be null)
    Parameters:
    catalog - a catalog name; must match the catalog name as it is stored in the database; "" retrieves those without a catalog; null means that the catalog name should not be used to narrow the search
    schema - a schema name; must match the schema name as it is stored in the database; "" retrieves those without a schema; null means that the schema name should not be used to narrow the search
    table - a table name; must match the table name as it is stored in the database
    Returns:
    ResultSet - each row is a primary key column description
    Throws:
    SQLException - if a database access error occurs

"

So, all in all, the SAP HANA JDBC driver works as expected.

- Lars