> ## Documentation Index
> Fetch the complete documentation index at: https://cockroachlabs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart with CockroachDB

export const InternalLink = ({version, path = "", children, ...props}) => {
  let detectedVersion = version || "stable";
  if (typeof window !== 'undefined' && !version) {
    const match = window.location.pathname.match(/\/docs\/([^/]+)/);
    if (match) {
      detectedVersion = match[1];
    }
  }
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
  return <a href={`/docs/${detectedVersion}/${normalizedPath}`} {...props}>
      {children}
    </a>;
};

This page shows you how to use free trial credits to deploy a CockroachDB cluster on CockroachDB Standard and use sample code to run your first queries.

## Create a free trial cluster

1. <InternalLink version="cockroachcloud" path="create-an-account">Create a CockroachDB Cloud account</InternalLink>. If this is your first CockroachDB Cloud organization, it will be credited with \$400 in <InternalLink version="cockroachcloud" path="free-trial">free trial credits</InternalLink> to get you started.
2. On the **Get Started** page, click **Create cluster**.
3. On the **Select a plan** page, select **Standard**.
4. On the **Cloud & Regions** page, select a cloud provider (GCP or AWS).
5. In the **Regions** section, select a region for the cluster. Refer to <InternalLink version="cockroachcloud" path="regions">CockroachDB Cloud Regions</InternalLink> for the regions where CockroachDB Standard clusters can be deployed. To create a multi-region cluster, click **Add region** and select additional regions.
6. Click **Next: Capacity**.
7. On the **Capacity** page, keep the <InternalLink version="cockroachcloud" path="plan-your-cluster">**Provisioned capacity**</InternalLink> at the default value of 2 vCPUs.

   Click **Next: Finalize**.
8. On the **Finalize** page, name your cluster. If an active free trial is listed in the right pane, you will not need to add a payment method, though you will need to do this by the <InternalLink version="cockroachcloud" path="free-trial#add-payment-methods">end of the trial</InternalLink> to maintain your organization's clusters.

   Click **Create cluster**.

   Your cluster will be created in a few seconds and the **Create SQL user** dialog will display.

## Create a SQL user

The **Create SQL user** dialog allows you to create a new SQL user and password.

1. Enter a username in the **SQL user** field or use the one provided by default.
2. Click **Generate & save password**.
3. Copy the generated password and save it in a secure location.
4. Click **Next**.

   Currently, all new SQL users are created with admin privileges. For more information and to change the default settings, see <InternalLink path="managing-access#manage-sql-users-on-a-cluster">Managing SQL users on a cluster</InternalLink>.

## Connect to the cluster

Select a language to connect a sample application to your cluster. To connect to your cluster directly from the command line, refer to <InternalLink path="connect-to-your-cluster">Connect to a Standard Cluster</InternalLink>.

<Tabs>
  <Tab title="Java">
    Once you create a SQL user, the **Connect to cluster** dialog will show information about how to connect to your cluster.

    1. Select **Java** from the **Select option/language** dropdown.
    2. Copy the `JDBC_DATABASE_URL` environment variable command provided and save it in a secure location.

    <Note>
      The connection string is pre-populated with your username, password, cluster name, and other details. Your password, in particular, will be provided *only* once. Save it in a secure place (Cockroach Labs recommends a password manager) to connect to your cluster in the future. If you forget your password, a Cluster Admin can reset it. Refer to: <InternalLink path="managing-access#manage-sql-users-on-a-cluster">Managing SQL users on a cluster</InternalLink>
    </Note>

    ### Configure the connection environment variable

    In a terminal, set the `JDBC_DATABASE_URL` environment variable to the JDBC connection string:

    <CodeGroup>
      ```shell Mac or Linux theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
      export JDBC_DATABASE_URL="<jdbc-connection-string>"
      ```

      ```shell Windows theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
      $env:JDBC_DATABASE_URL = "<jdbc-connection-string>"
      ```
    </CodeGroup>

    The code sample uses the connection string stored in the environment variable `JDBC_DATABASE_URL` to connect to your cluster.

    ### Run the Java sample code

    1. Clone the `quickstart-code-samples` repo:

       ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
       git clone https://github.com/cockroachdb/quickstart-code-samples
       ```

    2. Navigate to the `java` directory of the repo:

       ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
       cd quickstart-code-samples/java
       ```

       The code sample in this directory does the following:

       1. Connects to CockroachDB Cloud with the [JDBC driver](https://jdbc.postgresql.org/) using the JDBC connection string set in the `JDBC_DATABASE_URL` environment variable.
       2. Creates a table.
       3. Inserts some data into the table.
       4. Reads the inserted data.
       5. Prints the data to the terminal.

    3. Run the application using `gradlew`:

       ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
       ./gradlew run
       ```

       The output should look like this:

       ```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
       > Task :app:run
       Hello world!

       BUILD SUCCESSFUL in 3s
       2 actionable tasks: 2 executed
       ```
  </Tab>

  <Tab title="Node.js">
    Once you create a SQL user, the **Connect to cluster** dialog will show information about how to connect to your cluster.

    1. Select **General connection string** from the **Select option** dropdown.
    2. Open the **General connection string** section, then copy the connection string provided and save it in a secure location.

    <Note>
      The connection string is pre-populated with your username, password, cluster name, and other details. Your password, in particular, will be provided *only* once. Save it in a secure place (Cockroach Labs recommends a password manager) to connect to your cluster in the future. If you forget your password, a Cluster Admin can reset it. Refer to: <InternalLink path="managing-access#manage-sql-users-on-a-cluster">Managing SQL users on a cluster</InternalLink>
    </Note>

    ### Configure the connection environment variable

    In a terminal, set the `DATABASE_URL` environment variable to the connection string:

    <CodeGroup>
      ```shell Mac or Linux theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
      export DATABASE_URL="<connection-string>"
      ```

      ```shell Windows theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
      $env:DATABASE_URL = "<connection-string>"
      ```
    </CodeGroup>

    The code sample uses the connection string stored in the environment variable `DATABASE_URL` to connect to your cluster.

    ### Run the Node.js sample code

    1. Clone the `quickstart-code-samples` repo:

       ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
       git clone https://github.com/cockroachdb/quickstart-code-samples
       ```

    2. Navigate to the `node` directory of the repo:

       ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
       cd quickstart-code-samples/node
       ```

       The code sample in this directory does the following:

       1. Connects to CockroachDB Cloud with the [node-postgres driver](https://node-postgres.com/) using the connection string set in the `DATABASE_URL` environment variable.
       2. Creates a table.
       3. Inserts some data into the table.
       4. Reads the inserted data.
       5. Prints the data to the terminal.

    3. Install the app requirements:

       ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
       npm install
       ```

    4. Run the app:

       ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
       node app.js
       ```

       The output will look like this:

       ```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
       Hello world!
       ```
  </Tab>
</Tabs>

## Learn more

Now that you have a CockroachDB Standard cluster running, try out the following:

* Build a simple CRUD application in <InternalLink version="stable" path="build-a-go-app-with-cockroachdb">Go</InternalLink>, <InternalLink version="stable" path="build-a-java-app-with-cockroachdb">Java</InternalLink>, <InternalLink version="stable" path="build-a-nodejs-app-with-cockroachdb">Node.js</InternalLink>, or <InternalLink version="stable" path="build-a-python-app-with-cockroachdb">Python</InternalLink>.
* Learn <InternalLink version="stable" path="sql-statements">CockroachDB SQL</InternalLink>.
* <InternalLink path="managing-access">Create and manage SQL users</InternalLink>.
* <InternalLink version="molt" path="migration-overview">Migrate your existing data</InternalLink>.

This page highlights just one way you can get started with CockroachDB. For information on other options that are available when creating a CockroachDB cluster, see the following:

* To create a Self-Hosted cluster, see <InternalLink version="stable" path="start-a-local-cluster">Start a Local Cluster</InternalLink>.
* To create a CockroachDB Advanced cluster, see <InternalLink path="quickstart-trial-cluster">Quickstart with CockroachDB Advanced</InternalLink>.
* To create a CockroachDB Standard cluster with other configurations (e.g., a different cloud provider, region, or provisioned capacity), see <InternalLink path="create-your-cluster">Create a CockroachDB Standard Cluster</InternalLink>.
* To connect to a CockroachDB Standard cluster with other options (e.g., a different SQL user) and connection methods (with an application or <InternalLink version="stable" path="third-party-database-tools">CockroachDB compatible tool</InternalLink> ), see <InternalLink path="connect-to-your-cluster">Connect to a CockroachDB Standard Cluster</InternalLink>.
