Exception happened when using GAE / J and Google Cloud SQL with multiple projects

the following exception occurred.

    The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:33)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1117)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:350)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2416)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2450)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2235)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:818)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
Caused by: java.net.SocketException: Unable to open connection to the instance: project-A:dba
    at com.mysql.jdbc.GoogleCloudSqlSocket.<init>(GoogleCloudSqlSocket.java:48)
    at com.mysql.jdbc.GoogleCloudSqlSocketFactory.connect(GoogleCloudSqlSocketFactory.java:81)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:300)
    ... 44 more
Caused by: java.io.FileNotFoundException: /cloudsql/project-A:dba(No such file or directory)
    at java.io.RandomAccessFile.open(Native Method)
    at java.io.RandomAccessFile.<init>(RandomAccessFile.java:247)
    at java.io.RandomAccessFile.<init>(RandomAccessFile...(length 8379)

      

I have two GAE / J projects and both reference one google cloud sql instance. ex)

  • project-A (gae / j) use project-A: dba (cloudsql)
  • project-B (gae / j) use project-A: dba (cloudsql)

such an exception occurred in project-B.

db connection setting is following.
////(in project-B java file)//////
String url = "jdbc:google:mysql://"+ "project-B" + ":db/db1";
Connection con = DriverManager.getConnection(url, properties);
////

      

This is mistake? or any mistake?

+3


source to share


1 answer


If the Cloud SQL instance is the same for both projects, then the "project X" used as the instance qualifier must be the same for both applications. This is the name of the project in which the Cloud SQL instance was created.

The DB host is embedded in Java as "jdbc: google: mysql: // your-project-id: your-instance-name /"



According to your example, this would be "project-A: db /".

Remember to authorize the project-B application to access the Cloud SQL instance.

+1


source







All Articles