Connect to your Tiger Cloud service
In this section, you create a connection to your service using an application in a single file. You can use any of your favorite build tools, including gradle or maven.
Create a directory containing a text file called
Main.java, with this content:From the command line in the current directory, run the application:
If the command is successful, Hello, World! line output is printed to your console.
Import the PostgreSQL JDBC driver. If you are using a dependency manager, include the [PostgreSQL JDBC Driver][pg-jdbc-driver-dependency] as a dependency.
Download the [JAR artifact of the JDBC Driver][pg-jdbc-driver-artifact] and save it with the
Main.javafile.Import the
JDBC Driverinto the Java application and display a list of available drivers for the check:Run all the examples:
If the command is successful, a string similar to org.postgresql.Driver@7f77e91b is printed to your console. This means that you are ready to connect to TimescaleDB from Java.
- Locate your TimescaleDB credentials and use them to compose a connection string for JDBC.
- password
- username
- host URL
- port
- database name
- Compose your connection string variable, using this format:
For more information about creating connection strings, see the [JDBC documentation][pg-jdbc-driver-conn-docs].
This method of composing a connection string is for test or development purposes only. For production, use environment variables for sensitive details like your password, hostname, and port number.
If the command is successful, a string similar to \{ApplicationName=PostgreSQL JDBC Driver\} is printed to your console.