- AWS Code Sample

This version of the AWS Code Sample Catalog has been replaced by the AWS Code Library, which contains new and updated code examples. demonstrates how to get an AWS Glue table.


To run this Java (SDK V2) code example, ensure that you have set up your development environment, including your credentials. For more information, see AWS SDK for Java 2.x Developer Guide.

/* Copyright, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ package com.example.glue; import; import; import; import; import; import; import java.time.Instant; import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.time.format.FormatStyle; import java.util.Locale; /** * Before running this Java V2 code example, set up your development environment, including your credentials. * * For more information, see the following documentation topic: * * */ public class GetTable { public static void main(String[] args) { final String usage = "\n" + "Usage:\n" + " <dbName> <tableName>\n\n" + "Where:\n" + " dbName - The database name. \n" + " tableName - The name of the table. \n"; if (args.length != 2) { System.out.println(usage); System.exit(1); } String dbName = args[0]; String tableName = args[1]; Region region = Region.US_EAST_1; GlueClient glueClient = GlueClient.builder() .region(region) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); getGlueTable(glueClient, dbName, tableName); glueClient.close(); } public static void getGlueTable(GlueClient glueClient, String dbName, String tableName ) { try { GetTableRequest tableRequest = GetTableRequest.builder() .databaseName(dbName) .name(tableName) .build(); GetTableResponse tableResponse = glueClient.getTable(tableRequest); Instant createDate = tableResponse.table().createTime(); // Convert the Instant to readable date. DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDateTime( FormatStyle.SHORT ) .withLocale( Locale.US) .withZone( ZoneId.systemDefault() ); formatter.format( createDate ); System.out.println("The create date of the table is " + createDate ); } catch (GlueException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } } }