You can use either the PostgreSQL JDBC driver or the Spanner JDBC driver with a Spanner PostgreSQL-dialect database. This page explains how to connect to your database with these drivers.
PostgreSQL JDBC driver
This section explains how to connect the PostgreSQL JDBC driver to a PostgreSQL-dialect database in Spanner. JDBC is the standard Java driver for PostgreSQL.
If you use the PostgreSQL JDBC driver, you must use PGAdapter to translate between the PostgreSQL network protocol and the Spanner network protocol. You can add PGAdapter as a dependency and run it in-process with your application.
- Add PGAdapter and the PostgreSQL JDBC driver as dependencies
to your application.
- Start PGAdapter in-process with your application.
OptionsMetadata.Builder builder =