0
votes

I am trying to connect to Cloud Sql 2nd generation by using jdbc connector, by typing:

url = jdbc:google:mysql://project:region:instance/database?user=root

However, when doing this:

DriverManager.getConnection(url);

All I get is a null value.

I did not experience any trouble with first generation and old connection string, but I am not able to get this one working.

Anything in particular that I should consider like settings, missing code/connector? Any help will be greatly appreciated.

Thanks in advance!

1
It's somewhat unlikely that DriverManager.getConnection() would return null. Can you double check that you are not catching SQLException and leaving the connection variable as null? Can you include a bigger excerpt from your code including any exception handling you have? - Vadim
Thank you for your message, Vadim. Actually, the dump from the SqlException catch was not being logged, I had to add a Exception catch, and could find the problem, will post it as an answer because it is something I would like to post for everyone trying to connect to second generation. Regards! - Gabriel O

1 Answers

0
votes

Thanks to Vadim suggestion, I could find that there was a problem sending the wrong credentials to the database.

I will post the jdbc connection string here, since I could not find the complete way for the connection string in any page, I just found separate portions to build it.

Here it goes:

url = "jdbc:google:mysql://<your-project-id>:<your-cloud-sql-region>:<your-cloud-sql-instance>/<your-database-name>?user=<your-user>&password=<your-password>";

Hope this can help to save some time!