Reputation: 31
I want to connect Google Cloud MySQL instance using hibernate.
But I don't know what I need to write into my hibernate.cfg.xml
file.
<property name="connection.driver.class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://google/DB_Name?cloudSqlInstance=Connestion_Name;socketFactory=com.google.cloud.sql.mysql.SocketFactory;</property>
<property name="connection.username">User_Name</property>
<property name="connection.password">Password</property>
I am writing this but I am getting error
Exception in thread "main" org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Caused by: org.hibernate.exception.JDBCConnectionException: Error calling DriverManager#getConnection
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
Caused by: java.net.UnknownHostException: Google
I had added all IPs into Authorization.
Upvotes: 0
Views: 143
Reputation: 820
Never used google cloud but you should have a public url for your db instance(i think it could be something like www.google.com/xxx/ or similar) and you should replace //google/DB_Name with that one
Upvotes: 0