生产时Google App Engine和Google Cloud SQL连接问题

时间:2022-08-22 10:19:26

When I connect to Google MySQL account locally, it retrieve records from cloud MySQL table. But when I deploy my application on production, records are not coming but 200 OK is coming.

当我在本地连接到Google MySQL帐户时,它会从云MySQL表中检索记录。但是当我在生产中部署我的应用程序时,记录不会出现,但200 OK即将到来。

I've already tried

我已经试过了

 String url = null;
try {
  if (SystemProperty.environment.value() ==
      SystemProperty.Environment.Value.Production) {
    // Load the class that provides the new "jdbc:google:mysql://" prefix.
    Class.forName("com.mysql.jdbc.GoogleDriver");
    url = "jdbc:google:mysql://your-project-id:your-instance-name/guestbook?user=root";
  } else {
    // Local MySQL instance to use during development.
    Class.forName("com.mysql.jdbc.Driver");
    url = "jdbc:mysql://127.0.0.1:3306/guestbook?user=root";

    // Alternatively, connect to a Google Cloud SQL instance using:
    // jdbc:mysql://pi-address-of-google-cloud-sql-instance:3306/guestbook?user=root
  }
} catch (Exception e) {
  e.printStackTrace();
  return;
}

I have enable the connector using java 1.7 version

我已经使用java 1.7版本启用了连接器

1 个解决方案

#1


If you have not linked your App Engine's Application ID to the Authorized App Engine Applications' list for Cloud SQL instance, you may need to link those two, because only apps listed there will be allowed to access your Cloud SQL instance; and those must be located in the same region as well.

如果您尚未将App Engine的应用程序ID链接到Cloud SQL实例的授权应用程序引擎应用程序列表,则可能需要将这两者联系起来,因为只有那里列出的应用程序才能访问您的Cloud SQL实例;那些也必须位于同一地区。

Also, you should add

另外,你应该添加

<use-google-connector-j>true</use-google-connector-j>

in appengine-web.xml.

#1


If you have not linked your App Engine's Application ID to the Authorized App Engine Applications' list for Cloud SQL instance, you may need to link those two, because only apps listed there will be allowed to access your Cloud SQL instance; and those must be located in the same region as well.

如果您尚未将App Engine的应用程序ID链接到Cloud SQL实例的授权应用程序引擎应用程序列表,则可能需要将这两者联系起来,因为只有那里列出的应用程序才能访问您的Cloud SQL实例;那些也必须位于同一地区。

Also, you should add

另外,你应该添加

<use-google-connector-j>true</use-google-connector-j>

in appengine-web.xml.