Search code examples
javagoogle-cloud-sql

I need to connect to Google cloud mysql using java but without using spring boot?


can someone help me with any sample working code or any project that I can look at? I have been searching this on google for few days but I always end up an answer with spring boot but I need to connect without using spring boot. I need to write automated API tests where I have to connect to cloud Sql fetch the data from Db and validate it.


Solution

  • As @siamsot mentioned, there is an article in the official GCP documentation on how to connect to a Cloud SQL instance.

    Basically, you have the following options to connect to a Cloud SQL instance:

    • By using the proxy (Second Generation instances only)
    • By configuring access for one or more public IP addresses
    • By using the JDBC Socket Factory (for the Java programming language, Second Generation instances only)
    • By using the Cloud SQL Proxy library (for the Go programming language, Second Generation instances only)