Skip to main content

Connect to JDBC

JDBC is a Java API for connecting to relational databases. Create a JDBC resource to connect Retool to any database with a JDBC driver, including databases that don't have a native Retool integration.

What you can do with JDBC in Retool

After you create a JDBC resource in Retool, you can:

  • Query data with SQL, including joins, aggregations, and subqueries.
  • Insert, update, and delete records with SQL statements.
  • Connect databases that don't have a native Retool integration by supplying your own JDBC driver.
  • Run scheduled JDBC queries in Retool Workflows.
  • Build dashboards and apps that display JDBC query results in charts, tables, and other components.
  • Give Retool Agents typed, structured access to JDBC queries as custom tools.
Best practice

If Retool has a native integration for your database, use it instead for a more seamless setup experience.

Before you begin

To connect JDBC to Retool, you need the following:

  • A supported driver: Cloud organizations can connect using one of Retool's bundled JDBC drivers (DB2, ClickHouse, Trino, Ingres, or Hive).
  • Credentials: A connection string with any credentials your database requires.
  • Retool permissions: Ability to create and manage resources in your organization.

Create a JDBC resource

Follow these steps to create a JDBC resource in your Retool organization.

Create a new resource

In your Retool organization, navigate to Resources in the main navigation and click Create newResource. Search for JDBC and click the JDBC tile to begin configuration.

JDBC resource configuration form.

Configure general settings

Specify a name and description for the resource that indicates which database it connects to. The description provides more context to users and Assist about how to use the resource.

Example nameExample description
Analytics warehouse (JDBC)A JDBC connection to the analytics data warehouse using the Trino driver.
Legacy Vertica (JDBC)A JDBC connection to the legacy Vertica database using a custom driver.

Configure resource credentials

Configure the connection settings for your JDBC resource.

Driver name

Select one of Retool's bundled drivers: DB2, ClickHouse, Trino, Ingres, or Hive. Retool automatically populates a schema query for the selected driver.

Connection string

Provide a JDBC connection string that includes your database's host, port, and credentials.

Example
jdbc:trino://host:443/catalog

Configure advanced options

Configure optional settings available under the Advanced options section of the resource configuration form.

Disable converting queries to prepared statements

By default, Retool uses prepared statements for JDBC queries, which improves performance and prevents SQL injection. Disable this option only if your driver or database doesn't support prepared statements.

Outbound region

If your organization uses outbound regions, select the region that should be used for requests to your database. This controls which geographic region your requests originate from.

Test the connection

Click Test connection to verify Retool can connect to your database. If the test succeeds, you see a success message. If it fails, check the following:

  • Driver name: Verify the driver class name is correct and, for self-hosted instances, that the driver .jar file is in the configured JDBC directory.
  • Connection string: Verify the host, port, and credentials in your connection string are correct.
  • Network access: Ensure your database accepts connections from Retool's IP addresses or your self-hosted instance's network.
Best practice

After testing the connection, click View in console to open the Debug Tools console. The console displays detailed information about the test, including the test query executed, execution time, and error details if the test fails.

Save the resource

Click Create resource to save your JDBC resource. You can now use it in queries across your Retool apps and automations.

Interact with JDBC data

Once you've created a JDBC resource, you can interact with JDBC data using Retool.

Switch to the new app builder

Retool recommends using the new app builder so you can use natural language to build React-based apps using AI.

  • To use JDBC data in the app builder, reference the resource in the prompt with @, such as @Analytics warehouse (JDBC). Refer to the data and functions documentation to learn more.
  • For classic apps, workflows, and agents, refer to the SQL queries documentation to learn how to write a resource query.

Best practices

Follow these best practices to maintain the security of your JDBC resource.

  • Store credentials securely: Retool encrypts your JDBC connection string automatically, so you don't need to route it through a separate secrets store.
  • Use a read-only user for read-heavy resources: Create a dedicated database user with only the permissions a resource actually needs, and use a read-only user for resources that only query data.
  • Keep driver .jar files up to date: Outdated drivers can carry unresolved security vulnerabilities. Check your database vendor's site periodically for a newer stable driver.
  • Use resource environments: Organizations on an Enterprise plan can configure multiple resource environments to maintain separate JDBC credentials for production, staging, and development.