3

I wonder how come this error is thrown while hosting my project in APP ENGINE, I have added lots of logging just for analysis sake. When I use the com.mysql.jdbc.Driver using ip from my local it works. Kindly help !!

    String name = "Vinodh";
    String url = null;
    try {
        Class.forName("com.mysql.jdbc.GoogleDriver");
        url = "jdbc:google:mysql://xxxxxxx:xxxxxx/vinodh?user=root&password=xxxxxx";

        // Statements allow to issue SQL queries to the database
        log.info("Initiate Connection");
        Connection conn = DriverManager.getConnection(url);
        log.info("Got Connection");
        Statement statement = conn.createStatement();
        // Result set get the result of the SQL query
        ResultSet resultSet = statement

                .executeQuery("select * from Family");
        log.info("Entering While");
        while(resultSet.next()){
             log.info("Entered While");
            String test = resultSet.getString("Name");
            System.out.println(test);

            name = test+test+test;
        }
Vinodh Thiagarajan
  • 758
  • 3
  • 9
  • 19

2 Answers2

2

As shwown in this tutorial, during development you should use the normal mysql driver and only appengine use the Google mysql driver

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

Also double check that you have enabled MySQL Connector/J for your application (it's not done by default)

https://developers.google.com/appengine/docs/java/cloud-sql/#enable_connector_j

<?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>
Frederic Close
  • 9,389
  • 6
  • 56
  • 67
  • Thanks it worked. As you see this is the first time I'm trying to deploy using MySQl.Currently I'm getting the below error, – Vinodh Thiagarajan Nov 24 '13 at 09:48
  • com.connecttest.Connector2Servlet doGet: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES) – Vinodh Thiagarajan Nov 24 '13 at 09:49
  • Found it from stack overflow :-). root musnt use password. Thanks again. – Vinodh Thiagarajan Nov 24 '13 at 09:52
  • I'm currently getting this exception ([see here](http://stackoverflow.com/questions/37644148/java-lang-illegalstateexception-could-not-load-jdbc-driver-class-com-mysql-jdb)) but in my case I am going from Google Flexible to Cloud SQL. Do I have to specify `use-google-connector-j` somewhere too? – Stefan Falk Jun 05 '16 at 16:26
0

Appearently they removed this quietly. It's not even in the docs of appengine-web.xml anymore.

Use the standard com.mysql.jdbc.Driver but update your JDBC url for:

jdbc:mysql://google/[your-db-schema]
   ?user=root
   &password=[your-db-passord]
   &socketFactory=com.google.cloud.sql.mysql.SocketFactory
   &cloudSqlInstance=[your-db-project-id]:[your-db-region]:[your-db-intance]

Add also to your gradle:

dependencies {
   ...
   implementation("mysql:mysql-connector-java:8.0.29")
   implementation("com.google.cloud.sql:mysql-socket-factory-connector-j-8:1.5.0")
}

Note the "google" in the URI. There's no place in the docs saying that you need it, but you have to.

Github official page guide

Allan Veloso
  • 5,823
  • 1
  • 38
  • 36