【问题标题】:Issue with connection from Google App Engine and Google Cloud SQL on productionGoogle App Engine 和 Google Cloud SQL 在生产环境中的连接问题
【发布时间】:2015-07-18 00:50:20
【问题描述】:

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

我已经试过了

 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;
}

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

【问题讨论】:

    标签: java mysql google-app-engine cloud google-cloud-storage


    【解决方案1】:

    如果您尚未将 App Engine 的应用程序 ID 链接到 Cloud SQL 实例的授权 App Engine 应用程序列表,您可能需要将这两个链接起来,因为只有其中列出的应用程序才能访问您的 Cloud SQL 实例;并且它们也必须位于同一区域。

    另外,你应该添加

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

    在 appengine-web.xml 中。

    【讨论】:

      猜你喜欢
      • 2017-12-05
      • 1970-01-01
      • 1970-01-01
      • 2015-12-18
      • 1970-01-01
      • 1970-01-01
      • 2016-11-05
      • 1970-01-01
      • 2014-07-19
      相关资源
      最近更新 更多