I have deployed on appengine a basic java web app that is supposed to connect to a postgresql instance on Cloud SQL (works locally). After deployment It (wrongly?) raise this exception when I browse the page that tries to connect to the DB:
org.postgresql.Driver connect: Unexpected connection error: (Driver.java:271) java.lang.RuntimeException: The Google Cloud SQL API is not enabled for project [ad*****manager-XXXXXXX]. Please use the Google Developers Console to enable it: https://console.cloud.google.com/apis/api/sqladmin/overview?project=ad*****manager-XXXXXXX
Here is the part of the code that fails:
Class.forName("org.postgresql.Driver");
connection = DriverManager.getConnection(dburl, dbuser, dbpwd);
And the connection url:
jdbc:postgresql://google/name_of_my_database?useSSL=false&socketFactoryArg=ad*****manager-XXXXXXX:europe-west1:XXXX-pgdb-preprod&socketFactory=com.google.cloud.sql.postgres.SocketFactory
Actually I had to enable the SQL API not in the project that hosts the DB as said in the error message but in the project that hosts the application
To do so, go in the API section, choose library and search for SQL API (see screenshot below)