-1

I'm trying to get all database metadata from an Access database using the UCanAccess JDBC driver but I need to change my resultset type to navigate in the resultset but how to set the good type when my resultset are created with method from the interface databasemetadata ? code here

 v_resultPrimaryKey = p_metadata.getPrimaryKeys(null, Tools.getDBName(), p_table);

        ResultSet v_resultColumn = p_metadata.getColumns(null, Tools.getDBName(), p_table, null);

        v_resultPrimaryKey.first();

        String v_pkName = v_resultPrimaryKey.getString("COLUMN_NAME");
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
kazor02x
  • 43
  • 2
  • 8

1 Answers1

0

You don't need to change the ResultSet type in order to retrieve the primary key information. All you need to do is something like this ...

try (Connection conn = DriverManager.getConnection(connUrl)) {
    try (ResultSet rs = conn.getMetaData().getPrimaryKeys(null, null, "InvoiceDetail")) {
        while (rs.next()) {
            System.out.printf("%s (%d)%n", 
                    rs.getString("COLUMN_NAME"), 
                    rs.getInt("KEY_SEQ"));
        }
    }
}

... which for a table like this ...

InvoiceDetail.png

... will produce output like this:

InvoiceNumber (1)
LineItemNumber (2)
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418