简体   繁体   中英

Issue with connection from Google App Engine and Google Cloud SQL on production

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.

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

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.

Also, you should add

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

in appengine-web.xml.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM