Connect a Java application to Neon
Set up a Neon project in seconds and connect with JDBC or Spring Data
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. Postgres 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 JDBC API documentation, and the 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 your project settings and click Create 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:
You can find all of the connection details listed above in the Connection Details widget on the Neon Dashboard. For more information, see Connect from any application.
Connect from Spring Data
Spring Data relies on JDBC and Postgres drivers to connect to Postgres 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:
Refer to the Connect with JDBC section above for information about obtaining connection details for your Neon database.
Last updated on