Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.
Jelaskan database
Anda dapat menggunakan cuplikan kode berikut untuk mendapatkan informasi tentang atribut database yang baru Anda buat.
catatan
Cuplikan kode ini didasarkan pada contoh aplikasi lengkap. GitHub
- Java
-
public void describeDatabase() { System.out.println("Describing database"); final DescribeDatabaseRequest describeDatabaseRequest = new DescribeDatabaseRequest(); describeDatabaseRequest.setDatabaseName(DATABASE_NAME); try { DescribeDatabaseResult result = amazonTimestreamWrite.describeDatabase(describeDatabaseRequest); final Database databaseRecord = result.getDatabase(); final String databaseId = databaseRecord.getArn(); System.out.println("Database " + DATABASE_NAME + " has id " + databaseId); } catch (final Exception e) { System.out.println("Database doesn't exist = " + e); throw e; } }
- Java v2
-
public void describeDatabase() { System.out.println("Describing database"); final DescribeDatabaseRequest describeDatabaseRequest = DescribeDatabaseRequest.builder() .databaseName(DATABASE_NAME).build(); try { DescribeDatabaseResponse response = timestreamWriteClient.describeDatabase(describeDatabaseRequest); final Database databaseRecord = response.database(); final String databaseId = databaseRecord.arn(); System.out.println("Database " + DATABASE_NAME + " has id " + databaseId); } catch (final Exception e) { System.out.println("Database doesn't exist = " + e); throw e; } }
- Go
-
describeDatabaseOutput, err := writeSvc.DescribeDatabase(describeDatabaseInput) if err != nil { fmt.Println("Error:") fmt.Println(err) } else { fmt.Println("Describe database is successful, below is the output:") fmt.Println(describeDatabaseOutput) }
- Python
-
def describe_database(self): print("Describing database") try: result = self.client.describe_database(DatabaseName=Constant.DATABASE_NAME) print("Database [%s] has id [%s]" % (Constant.DATABASE_NAME, result['Database']['Arn'])) except self.client.exceptions.ResourceNotFoundException: print("Database doesn't exist") except Exception as err: print("Describe database failed:", err)
- Node.js
-
Cuplikan berikut digunakan AWS SDK untuk JavaScript v3. Untuk informasi selengkapnya tentang cara menginstal klien dan penggunaan, lihat Timestream Write Client - AWS SDK untuk JavaScript v3.
Lihat juga kelas DescribeDatabaseCommand dan DescribeDatabase
import { TimestreamWriteClient, DescribeDatabaseCommand } from "@aws-sdk/client-timestream-write"; const writeClient = new TimestreamWriteClient({ region: "us-east-1" }); const params = { DatabaseName: "testDbFromNode" }; const command = new DescribeDatabaseCommand(params); try { const data = await writeClient.send(command); console.log(`Database ${data.Database.DatabaseName} has id ${data.Database.Arn}`); } catch (error) { if (error.code === 'ResourceNotFoundException') { console.log("Database doesn't exist."); } else { console.log("Describe database failed.", error); throw error; } }
Cuplikan berikut menggunakan gaya AWS SDK for JavaScript V2. Hal ini didasarkan pada contoh aplikasi di Node.js sampel Amazon Timestream untuk LiveAnalytics aplikasi
pada. GitHub async function describeDatabase () { console.log("Describing Database"); const params = { DatabaseName: constants.DATABASE_NAME }; const promise = writeClient.describeDatabase(params).promise(); await promise.then( (data) => { console.log(`Database ${data.Database.DatabaseName} has id ${data.Database.Arn}`); }, (err) => { if (err.code === 'ResourceNotFoundException') { console.log("Database doesn't exist."); } else { console.log("Describe database failed.", err); throw err; } } ); }
- .NET
-
public async Task DescribeDatabase() { Console.WriteLine("Describing Database"); try { var describeDatabaseRequest = new DescribeDatabaseRequest { DatabaseName = Constants.DATABASE_NAME }; DescribeDatabaseResponse response = await writeClient.DescribeDatabaseAsync(describeDatabaseRequest); Console.WriteLine($"Database {Constants.DATABASE_NAME} has id:{response.Database.Arn}"); } catch (ResourceNotFoundException) { Console.WriteLine("Database does not exist."); } catch (Exception e) { Console.WriteLine("Describe database failed:" + e.ToString()); } }