Could not create socket factory 'com.google.cloud.sql.mysql.SocketFactory;'
Asked Answered
I

1

4

I can't seem to get this to work ..

I am using Google Flexible Environment and want to connect to my Second Generation Cloud SQL database. I am currently getting this exception:

[main] ERROR com.mahlzeit.server.BootstrappingServerConfig - Error trying to migrate SQL scripts ..
org.flywaydb.core.api.FlywayException: Unable to obtain Jdbc connection from DataSource
    at org.flywaydb.core.internal.util.jdbc.JdbcUtils.openConnection(JdbcUtils.java:56)
    at org.flywaydb.core.Flyway.execute(Flyway.java:1385)
    at org.flywaydb.core.Flyway.migrate(Flyway.java:1006)
    ...
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create socket factory 'com.google.cloud.sql.mysql.SocketFactory;' due to underlying exception:
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    ...
Caused by: java.lang.ClassNotFoundException: com/google/cloud/sql/mysql/SocketFactory;
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at com.mysql.jdbc.MysqlIO.createSocketFactory(MysqlIO.java:3321)
    ...

This is how I am configuring my DataSource:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://google/mz_db?cloudSqlInstance=mz-test:us-central1:mz-life-cloudsql-prod&amp;socketFactory=com.google.cloud.sql.mysql.SocketFactory;" />
    <property name="username" value="root" />
    <property name="password" value="" />
</bean>

I have added the mysql-socket-factory as dependency:

<dependency>
    <groupId>com.google.cloud.sql</groupId>
    <artifactId>mysql-socket-factory</artifactId>
    <version>1.0.0</version>
</dependency>

so why am I getting this exception?

Immanent answered 5/6, 2016 at 21:45 Comment(1)
Is this your configuration on the local machine or in production? I'm having problem with flexible env to SQL cloud connection in production. Which is your Driver classname?Senskell
M
4

You have a semicolon at the end so it's trying to load a class called com.google.cloud.sql.mysql.SocketFactory; Try removing the semicolon at the end.

Mazzola answered 5/6, 2016 at 21:49 Comment(1)
Yep, it was the & to &amp; issue and then remove the ; which was what Eclipse suggested as I used just &. If "java.lang.IllegalAccessError: tried to access field sun.security.ssl.Handshaker.localSupportedSignAlgs from class sun.security.ssl.ClientHandshaker" rings a bell please let me know ^^Immanent

© 2022 - 2024 — McMap. All rights reserved.