Code: Select all
String dbUser = "[email protected]";
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 [url=viewtopic.php?t=25360]environment[/url] 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: Es ist etwas Ungewöhnliches aufgetreten, das zum Ausfall des Treibers geführt hat. Bitte melden Sie diese Ausnahme.
Wir verwenden die folgenden Jars:

Wir sind nicht sicher, was diesen Fehler verursacht. Der gleiche Aufruf funktioniert, wenn ich die Basisauthentifizierung verwende. Wir hatten in GCP PostGreSQL ein temporäres Benutzerkonto mit Benutzername/Passwort eingerichtet, das über diesen Code funktioniert.
Mobile version