0
votes

I have a Java/Jetty based appengine project that successfully connects to Google cloud MySql server when using TCP connection with JDBC, BUT fails to connect to the same server when trying to make it through Instance name and JDBC socketFactory. the error I am getting in the GCP debug console:

"Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The >driver has not received any packets from the server."

try {
            Class.forName("com.mysql.jdbc.GoogleDriver");
            String url= String.format("jdbc:google:mysql:///"
                    + "MY_DB_NAME" + "?"
                    + "cloudSqlInstance=%s&"
                    + "socketFactory=%s&"
                    + "useSSL=false",
                    "PROJECT-ID:ZONE:INSTANCE_NAME", 
                    "com.google.cloud.sql.mysql.SocketFactory");

            return DriverManager.getConnection(url, USER_NAME, USER_PASSWORD);
        } catch (SQLException | ClassNotFoundException e) {
            e.printStackTrace();
            return null;
        }
1
Could you try changing the GoogleDriver to "com.mysql.jdbc.Driver"? Is the error happening locally or after deploying to GAE? Also, I would recommend you to follow the official docs on how to connect to Cloud SQL from App Engine - Jose V
I changed to "com.mysql.jdbc.Driver" but still not working with the same error. I am getting the error when deploying to GAE. - bouda04
I managed to make it work after replacing the url prefix from "jdbc:google:mysql:" to "jdbc:mysql:" - bouda04

1 Answers

0
votes

The problem might be in the public IP address that you specify in the cloud mysql instance. Just check the public IP address by typing What is my public IP? in the browser. Then update the public IP given for the google cloud instance. This might be help to solve your issue.