Utkarsh Sharma
Utkarsh Sharma

Reputation: 73

java.sql.SQLNonTransientConnectionException: Could not create connection to database server- Google Cloud Platform

I'm trying to create a spring boot application that inserts some data into GCP Mysql.But everytime I'm trying to run application it shows exception -

  java.sql.SQLNonTransientConnectionException: Could not create connection to database server.
Caused by: java.io.IOException: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials

Now following is my application.properties file.Actual paparmeters not defined here-

     spring.cloud.gcp.sql.database-name=DemoDatabase
        spring.cloud.gcp.sql.instance-connection-name=xxxxxxxxxxx
        spring.datasource.initialization-mode=always
spring.cloud.gcp.credentials.location=C:/Users/utkar/Downloads/spring-boot-7208e0222fb1.json
    spring.datasource.url=jdbc:mysql://google/DemoDatabase?cloudSqlInstance=XXXXXXXXXXX&socketFactory=com.google.cloud.sql.mysql.SocketFactory&useSSL=false
        spring.datasource.username=XXXXX
        spring.datasource.password=XXXXXX

Please help.Thanks in advance

Upvotes: 0

Views: 816

Answers (1)

Santi Wagner
Santi Wagner

Reputation: 328

Run the following command on the CLI:

gcloud auth application-default login

Upvotes: 2

Related Questions