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


On Mon, Oct 11, 2021 at 6:45 AM Tom Harris <t...@terratrue.com> wrote:

> 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
>
> --
> 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-appengine+unsubscr...@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
> <https://groups.google.com/d/msgid/google-appengine/792e5183-dea5-458f-8c44-abf185d5f8ebn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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-appengine+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/CAB9U9Q8aoaCaKy4wnH%3DJU7mCfZu27jBkZmdSNgitDD2HxYD-7g%40mail.gmail.com.

Reply via email to