-2

At this moment try deploy a simple Java aplication on the Google cloud platform.But only the start page (login) and the registration page are open for now. When I try to register a new user I get an error:

org.springframework.orm.jpa.JpaSystemException: Could not open connection; nested exception is org.hibernate.exception.GenericJDBCException: Could not open connection
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException (HibernateJpaDialect.java:244)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible (HibernateJpaDialect.java:155)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible (AbstractEntityManagerFactoryBean.java:417)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible (ChainedPersistenceExceptionTranslator.java:59)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary (DataAccessUtils.java:213)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke (PersistenceExceptionTranslationInterceptor.java:147)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (ReflectiveMethodInvocation.java:179)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodIntercceptor.invoke (CrudMethodMetadataPostProcessor.java:122)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke (ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke (JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy42.findByUsername (Unknown Source)
at project.security.service.UserServiceImpl.findByUsername (UserServiceImpl.java:38)
at project.security.validator.UserValidator.validate (UserValidator.java:32)
at project.security.controller.UserController.registration (UserController.java:38)

I know that the problem with accessing the database is `Cloud MySQL. ' And I can not understand what I'm doing wrong.When I run the application on the local server everything is working fine.I tried various options for running the application, but the error is always the same. Link to the code https://github.com/Ditrim023/MVC_for_money. A link to the not working application change-curr.appspot.com . I will be happy with any help.

Ditrim023
  • 1
  • 1
  • Please read [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask) before attempting to ask more questions. –  Jun 23 '17 at 16:07
  • Please read [Why is “Can someone help me?” not an actual question?](https://meta.stackoverflow.com/questions/284236/why-is-can-someone-help-me-not-an-actual-question) before attempting to ask more questions. –  Jun 23 '17 at 16:07

2 Answers2

0

Following the java docs for Google Cloud, you have an invalid connection string in your properties file.

You have defined:

jdbc:google:mysql://exchange-6/secur?user=root

From the docs, try using

String jdbcUrl = String.format(
    "jdbc:mysql://google/%s?cloudSqlInstance=%s&"
        + "socketFactory=com.google.cloud.sql.mysql.SocketFactory",
    databaseName,
    instanceConnectionName);
Matt Clark
  • 27,671
  • 19
  • 68
  • 123
  • Unfortunately, this example does not work – Ditrim023 May 24 '17 at 16:21
  • 1
    Again, `does not work` is a term that does not fly here on SO. Post the **reasons** why it does not work. What is the problem with it? – Matt Clark May 24 '17 at 16:22
  • I just get this [example](https://github.com/GoogleCloudPlatform/cloud-sql-mysql-socket-factory/blob/master/examples/compute-engine/src/main/java/com/google/cloud/sql/mysql/example/ListTables.java) and launched it. And i get this result:`Exception in the thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)` – Ditrim023 May 24 '17 at 16:51
-1

Make sure in google cloud that you added your ip address to database permissions. Or add 0.0.0.0/0 to allow any IP address to connect to your database. However this is not recommended.

Alexandru Cancescu
  • 829
  • 1
  • 9
  • 19