Код: Выделить всё
String dbUser = "user@abc.iam.gserviceaccount.com";
String dbPass = "";
String dbName = "test";
String instanceConnectionName = "my-project:europe-west1:my-instance"; /
String serviceAccountPath = "/path/ords-labs-esb-sql-user-sa-key.json";
String jdbcUrl = String.format(
"jdbc:postgresql://google/%s?cloudSqlInstance=%s&socketFactory=com.google.cloud.sql.postgres.SocketFactory&useSSL=false",
dbName, instanceConnectionName );
// Set the environment variable for authentication
System.setProperty("GOOGLE_APPLICATION_CREDENTIALS", serviceAccountPath);
try {
Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection(jdbcUrl, dbUser, dbPass);
debugLog("Connected to PostgreSQL on GCP successfully!");
// Perform DB operations here
} catch (Exception e) {
debugLog(e.toString());
}
org.postgresql.util.PSQLException: произошло что-то необычное, что привело к сбою драйвера. Сообщите об этом исключении.
Мы используем указанные ниже банки:

Мы не уверены, что вызывает эту ошибку. Тот же вызов работает, если я использую базовую аутентификацию. Мы создали временную учетную запись пользователя с именем пользователя и паролем в GCP PostGreSQL, которая работает через этот код.
Подробнее здесь: https://stackoverflow.com/questions/798 ... entication
Мобильная версия