sql >> Base de Datos >  >> RDS >> Mysql

Error al conectarse a la instancia local de MySQL desde Google App Engine Java.

Primero, asegúrese de haber habilitado MySQL Connector/J en appengine-web.xml de la siguiente manera.

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
  ...
  <use-google-connector-j>true</use-google-connector-j>
</appengine-web-app>

Luego use algo como el siguiente fragmento de código para conectarse a la base de datos.

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/your-database?user=root";
} else {
    // Local MySQL instance to use during development.
    Class.forName("com.mysql.jdbc.Driver");
    url = "jdbc:mysql://127.0.0.1:3306/your-database?user=root";

    // Alternatively, connect to a Google Cloud SQL instance using:
    // jdbc:mysql://ip-address-of-google-cloud-sql-instance:3306/your-database?user=root
}

Puede encontrar más detalles aquí .