App Engine 11 with Cloud SQL mysql "No suitable driver"

950 views
Skip to first unread message

Tom Harris

unread,
Oct 11, 2021, 9:45:41 AM10/11/21
to Google App Engine
Hi all, running into a very thorny issue that I have spent considerable time on now, without a working solution.

We have a set of Java 8 AppEngine-based microservices that I am upgrading to Java 11 and Spring Boot. The services are using MySQL via Cloud SQL with Google's socket factory. Locally, we use the MySQL driver directly and the services run as expected.

However when I try to deploy out to a cloud environment, when the code tries to instantiate the Hikari connection pool using Cloud SQL, I receive the dreaded "No suitable driver" error from the JDBC DriverManager.

Our project includes these two dependencies:
<dependency>
  <groupId>com.google.cloud.sql</groupId>
  <artifactId>mysql-socket-factory-connector-j-8</artifactId>
  <version>1.3.3</version>
</dependency>
<dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>8.0.26</version>
</dependency>


Here is the code that is failing:
HikariConfig config = new HikariConfig();
config.addDataSourceProperty("useSSL", "false");
config.addDataSourceProperty("useUnicode", "true");
config.addDataSourceProperty("characterEncoding", "UTF-8");
config.setRegisterMbeans(true);

config.setJdbcUrl("jdbc:mysql:///dbname");
config.setUsername(dbUser);
config.setPassword(dbPassword);
config.addDataSourceProperty("socketFactory", "com.google.cloud.sql.mysql.SocketFactory");
config.addDataSourceProperty("cloudSqlInstance", instanceConnectionName);

return new HikariDataSource(config);


And every time I try to fire up the service after deploying it to the cloud, I am seeing the error:

Caused by: java.lang.RuntimeException: Failed to get driver instance for jdbcUrl=jdbc:mysql:///dbname  at com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:114) at com.zaxxer.hikari.pool.PoolBase.initializeDataSource(PoolBase.java:331) at com.zaxxer.hikari.pool.PoolBase.<init>(PoolBase.java:114) at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:108) at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:81) at com.terratrue.db.DataSources.initDataSourceForCloudEnvironmentForUser(DataSources.java:276)
Caused by: java.sql.SQLException: No suitable driver at java.sql/java.sql.DriverManager.getDriver(DriverManager.java:298) at com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:106) ... 53 common frames omitted"

I have searched the internet for anything that would help resolve this issue, but I can't seem to find a relevant solution. The jar files for both libs are found in the app-staging folder, so I know they are getting deployed with the service.

Does anyone have suggestions as to what to do next?

Thanks,
Tom Harris

Tom Harris

unread,
Oct 11, 2021, 4:04:24 PM10/11/21
to google-a...@googlegroups.com
I posted this a week ago, and I solved this issue - I just had to add a `Class.forName("com.mysql.cj.jdbc.Driver")` call, which was not needed in App Engine 8 with Java 8 when running in the cloud, but apparently it is now required. Without this, the database connection pool just cannot initialize, and all you get is a stack trace which ultimately ends with "No suitable driver".

Thanks,
Tom Harris


--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-appengine/792e5183-dea5-458f-8c44-abf185d5f8ebn%40googlegroups.com.

Ludovic Champenois

unread,
Oct 11, 2021, 8:23:51 PM10/11/21
to Google App Engine
Hi,
Thanks for the update and the solution,
We are looking and trying to understand the delta between the 2 runtimes...
Just to be sure, you are using the new Beta Java11 runtime with bundled APIs (so using appengine-web.xml), right?
Ludo

Tom Harris

unread,
Oct 13, 2021, 1:40:38 PM10/13/21
to google-a...@googlegroups.com

No, we are using pure app.yaml, no more appengine-web.xml in our modules.

Ludovic Champenois

unread,
Oct 18, 2021, 10:42:24 AM10/18/21
to Google App Engine
So it seems a generic Java well known error
Maybe the GAE Java8 runtime is a bit smarter and does this for you.
Anyway, it seems what your are doing is now the right thing,
Cheers,
Ludo

Ludovic Champenois

unread,
Oct 18, 2021, 10:46:21 AM10/18/21
to Google App Engine
Reply all
Reply to author
Forward
0 new messages