Related 
documentation: 
https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-usagenotes-connect-drivermanager.html

On Monday, October 18, 2021 at 4:42:24 PM UTC+2 Ludovic Champenois wrote:

> So it seems a generic Java well known error
>
> https://stackoverflow.com/questions/22384710/java-sql-sqlexception-no-suitable-driver-found-for-jdbcmysql-localhost3306
> 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
>
> On Wednesday, October 13, 2021 at 7:40:38 PM UTC+2 [email protected] 
> wrote:
>
>>
>> No, we are using pure app.yaml, no more appengine-web.xml in our modules.
>>
>> On Mon, Oct 11, 2021 at 5:24 PM 'Ludovic Champenois' via Google App 
>> Engine <[email protected]> wrote:
>>
>>> 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
>>>
>>> On Monday, October 11, 2021 at 1:04:24 PM UTC-7 [email protected] 
>>> wrote:
>>>
>>>> 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 <[email protected]> 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 [email protected].
>>>>> 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 [email protected].
>>>
>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/google-appengine/cbbd3ab0-e63e-470f-8415-11a8b3c11697n%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/google-appengine/cbbd3ab0-e63e-470f-8415-11a8b3c11697n%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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/b9aeb066-850b-4942-84bc-341a51a76f0fn%40googlegroups.com.

Reply via email to