创建条目
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis Java code sample demonstrates how to create an entry within Google Cloud Data Catalog.\u003c/p\u003e\n"],["\u003cp\u003eBefore running the sample, you must set up Application Default Credentials for authentication and follow the Java setup instructions in the Data Catalog quickstart guide.\u003c/p\u003e\n"],["\u003cp\u003eThe code requires you to replace placeholder values like project ID, location, entry group ID, and entry ID with your actual values.\u003c/p\u003e\n"],["\u003cp\u003eThe sample uses the \u003ccode\u003eDataCatalogClient\u003c/code\u003e to create an entry, specifying the entry group name, entry ID, and the entry details within a \u003ccode\u003eCreateEntryRequest\u003c/code\u003e object.\u003c/p\u003e\n"],["\u003cp\u003eThe sample demonstrates how to use the \u003ccode\u003ecreateEntry()\u003c/code\u003e method, which contains the logic to create an entry using the DataCatalogClient, and also shows how to properly set up and close the client.\u003c/p\u003e\n"]]],[],null,["# Create entry\n\nCreate an entry.\n\nCode sample\n-----------\n\n### Java\n\n\nBefore trying this sample, follow the Java setup instructions in the\n[Data Catalog quickstart using\nclient libraries](/data-catalog/docs/reference/libraries).\n\n\nFor more information, see the\n[Data Catalog Java API\nreference documentation](https://cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/overview).\n\n\nTo authenticate to Data Catalog, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n import com.google.cloud.datacatalog.v1.https://cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.CreateEntryRequest.html;\n import com.google.cloud.datacatalog.v1.https://cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.DataCatalogClient.html;\n import com.google.cloud.datacatalog.v1.https://cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.Entry.html;\n import com.google.cloud.datacatalog.v1.https://cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.EntryGroupName.html;\n import java.io.IOException;\n\n // Sample to create an entry\n public class CreateEntry {\n\n public static void main(String[] args) throws IOException {\n // TODO(developer): Replace these variables before running the sample.\n String projectId = \"MY_PROJECT_ID\";\n String location = \"MY_LOCATION\";\n String entryGroupId = \"MY_ENTRY_GROUP_ID\";\n String entryId = \"MY_ENTRY_ID\";\n https://cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.EntryGroupName.html entryGroupName = https://cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.EntryGroupName.html.of(projectId, location, entryGroupId);\n https://cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.Entry.html entry = https://cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.Entry.html.newBuilder().build();\n createEntry(entryGroupName, entryId, entry);\n }\n\n public static void createEntry(https://cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.EntryGroupName.html entryGroupName, String entryId, https://cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.Entry.html entry)\n throws IOException {\n // Initialize client that will be used to send requests. This client only needs to be created\n // once, and can be reused for multiple requests. After completing all of your requests, call\n // the \"close\" method on the client to safely clean up any remaining background resources.\n try (https://cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.DataCatalogClient.html client = https://cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.DataCatalogClient.html.create()) {\n https://cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.CreateEntryRequest.html request =\n https://cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.CreateEntryRequest.html.newBuilder()\n .setParent(entryGroupName.https://cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.EntryGroupName.html#com_google_cloud_datacatalog_v1_EntryGroupName_toString__())\n .https://cloud.google.com/java/docs/reference/google-cloud-datacatalog/latest/com.google.cloud.datacatalog.v1.CreateEntryRequest.Builder.html#com_google_cloud_datacatalog_v1_CreateEntryRequest_Builder_setEntryId_java_lang_String_(entryId)\n .setEntry(entry)\n .build();\n client.createEntry(request);\n System.out.println(\"Entry created successfully\");\n }\n }\n }\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=data_catalog)."]]