on 07-12-2013 3:43 PM
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.
Still occurring on:
Database product version: 1.00.62.380773
JDBC driver version: 1.00.60.Build 0379371-1510
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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:
- TABLE_CAT String => table catalog (may be
null
) - TABLE_SCHEM String => table schema (may be
null
) - TABLE_NAME String => table name
- COLUMN_NAME String => column name
- 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).
- 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
User | Count |
---|---|
83 | |
9 | |
9 | |
8 | |
7 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.