private <T> List<T> getColumnMetadata(Configuration conf, ColumnMetadataAccessor<T> colAccessor)
      throws HiveJdbcDatabaseAccessException {
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      initializeDatabaseConnection(conf);
      String tableName = getQualifiedTableName(conf);
      // Order is important since we need to obtain the original (as specified by the user) column names. JDBC_QUERY
      // may be a generated/optimized query set by CBO with potentially different aliases than the original columns. 
      String query = firstNonNull(selectAllFromTable(tableName), conf.get(Constants.JDBC_QUERY));
      String metadataQuery = getMetaDataQuery(query);
      LOGGER.debug("Query to execute is [{}]", metadataQuery);

      conn = dbcpDataSource.getConnection();
      ps = conn.prepareStatement(metadataQuery);
      rs = ps.executeQuery();

      return getColumnMetadata(rs, colAccessor);
    }
    catch (Exception e) {
      throw new HiveJdbcDatabaseAccessException("Caught exception while trying to get columns: " + e.getMessage(), e);
    }
    finally {
      cleanupResources(conn, ps, rs);
    }

  }
A data accessor that should in theory work with all JDBC compliant database drivers.
jdbc-handler/src/main/java/org/apache/hive/storage/jdbc/dao/GenericJdbcDatabaseAccessor.java