Connect a Java application to Neon
This guide describes how to create a Neon project and connect to it with Java Database Connectivity (JDBC) or from a Spring Data project that uses JDBC.
The JDBC API is a Java API for relational databases. PostgreSQL has a well-supported open-source JDBC driver which can be used to access Neon. All popular Java frameworks use JDBC internally. To connect to Neon, you are only required to provide a connection URL.
For additional information about JDBC, refer to the standard JDBC API documentation and PostgreSQL JDBC Driver documentation.
To connect to Neon with JDBC or from a Spring Data project:
Create a Neon project
If you do not have one already, create a Neon project. Save your connection details including your password. They are required when defining connection settings.
To create a Neon project:
- Navigate to the Projects page in the Neon Console.
- Click New Project.
- Specify a name, a PostgreSQL version, a region, and click Create Project.
For additional information about creating projects, see Set up a project.
Connect with JDBC
For a JDBC connection URL, replace the variables in the following URL string with your Neon project ID, database name, user, and password:
jdbc:postgresql://<endpoint_hostname>/<dbname>?user=<user>&password=<password>
where:
<endpoint_hostname>
the hostname of the branch endpoint. The endpoint hostname has anep-
prefix and appears similar to this:ep-tight-salad-272396.us-east-2.aws.neon.tech
.<dbname>
is the name of the database. The default Neon database isneondb
.<user>
is the database user.<password>
is the database user's password, which is provided to you when you create a project.
You can find all of the connection details listed above, except for your password, in the Connection Details widget on the Neon Dashboard. For more information, see Connect from any application. If you have misplaced your password, see Reset a password.
Connect from Spring Data
Spring Data relies on JDBC and PostgreSQL drivers to connect to PostgreSQL databases, such as Neon. If you are starting your project with Spring Initializr or connecting from an existing Spring Data project, ensure that the PostgreSQL database driver
dependency is installed.
Connecting from a Spring Data project requires specifying the datasource URL in your application.properties
file, as shown in the following example:
spring.datasource.url=jdbc:postgresql://<endpoint_hostname>/<dbname>?user=<user>&password=<password>
Refer to the Connect with JDBC section above for information about obtaining connection details for your Neon database.
Need help?
Send a request to support@neon.tech, or join the Neon community forum.