Create entry
Stay organized with collections
Save and categorize content based on your preferences.
Create an entry.
Code sample
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","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)."]]