Solucionado (ver solução)
Solucionado
(ver solução)
4
respostas

Não consigo conectar ao banco de dados

Segue todas as etapas de configuração, porém recebo essa tela de erro:

Configuration error
Cannot connect to database [default]

In /C:/Users/Victor/eclipse-workspace/activator-dist-1.3.12/bin/produtos-api/target/scala-2.11/classes/application.conf:346
342  # By convention, the default datasource is named `default`
343
344  # https://www.playframework.com/documentation/latest/Developing-with-the-H2-Database
345    default.driver = com.mysql.jdbc.Driver
346    default.url = "jdbc:mysql://localhost/produtos_api"
347    default.username = root
348    default.password = root
349
350  # You can turn on SQL logging for any datasource

o MySql está instalado corretamente e com as configurações de login e senha corretos, porem recebo essa mensagem.

4 respostas

Oi Victor, tudo bem?

tenta colocar a porta do MySQL:

"jdbc:mysql://localhost:3306/produtos_api"

Não deu certo. Continua o mesmo erro. No CMD eu recebo as seguitnes linhas:

! @7bgp0998f - Internal server error, for (GET) [/produto/novo] ->

play.api.Configuration$$anon$1: Configuration error[Cannot connect to database [default]]
        at play.api.Configuration$.configError(Configuration.scala:154)
        at play.api.Configuration.reportError(Configuration.scala:806)
        at play.api.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:48)
        at play.api.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:42)
        at scala.collection.immutable.List.foreach(List.scala:381)
        at play.api.db.DefaultDBApi.connect(DefaultDBApi.scala:42)
        at play.api.db.DBApiProvider.get$lzycompute(DBModule.scala:72)
        at play.api.db.DBApiProvider.get(DBModule.scala:62)
        at play.api.db.DBApiProvider.get(DBModule.scala:58)
        at com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:81)
Caused by: play.api.Configuration$$anon$1: Configuration error[Failed to initialize pool: Could not create connection to database server.]
        at play.api.Configuration$.configError(Configuration.scala:154)
        at play.api.PlayConfig.reportError(Configuration.scala:996)
        at play.api.db.HikariCPConnectionPool.create(HikariCPModule.scala:70)
        at play.api.db.PooledDatabase.createDataSource(Databases.scala:199)
        at play.api.db.DefaultDatabase.dataSource$lzycompute(Databases.scala:123)
        at play.api.db.DefaultDatabase.dataSource(Databases.scala:121)
        at play.api.db.DefaultDatabase.getConnection(Databases.scala:142)
        at play.api.db.DefaultDatabase.getConnection(Databases.scala:138)
        at play.api.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:44)
        at play.api.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:42)
Caused by: com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Could not create connection to database server.
        at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:512)
        at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:105)
        at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:71)
        at play.api.db.HikariCPConnectionPool$$anonfun$1.apply(HikariCPModule.scala:58)
        at play.api.db.HikariCPConnectionPool$$anonfun$1.apply(HikariCPModule.scala:54)
        at scala.util.Try$.apply(Try.scala:192)
        at play.api.db.HikariCPConnectionPool.create(HikariCPModule.scala:54)
        at play.api.db.PooledDatabase.createDataSource(Databases.scala:199)
        at play.api.db.DefaultDatabase.dataSource$lzycompute(Databases.scala:123)
        at play.api.db.DefaultDatabase.dataSource(Databases.scala:121)
Caused by: 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)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:400)
        at com.mysql.jdbc.Util.getInstance(Util.java:383)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:958)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:937)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:872)
Caused by: java.lang.NullPointerException: null
        at com.mysql.jdbc.ConnectionImpl.getServerCharset(ConnectionImpl.java:2999)
        at com.mysql.jdbc.MysqlIO.sendConnectionAttributes(MysqlIO.java:1885)
        at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1814)
        at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1207)
        at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2249)
        at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2280)
        at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2079)
        at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:794)
        at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

Vi que não estava colocando a senha do MySql entre aspas. Resolvi essa questão, porem o erro persiste. Percebi que a inserção da porta tirou o erro anterior, mas ainda assim não consigo conectar. Segue o erro que visualizo:

! @7bgp2k0f8 - Internal server error, for (GET) [/produto/novo] ->

play.api.Configuration$$anon$1: Configuration error[Failed to initialize pool: Could not create connection to database server.]
        at play.api.Configuration$.configError(Configuration.scala:154)
        at play.api.PlayConfig.reportError(Configuration.scala:996)
        at play.api.db.HikariCPConnectionPool.create(HikariCPModule.scala:70)
        at play.api.db.PooledDatabase.createDataSource(Databases.scala:199)
        at play.api.db.DefaultDatabase.dataSource$lzycompute(Databases.scala:123)
        at play.api.db.DefaultDatabase.dataSource(Databases.scala:121)
        at play.api.db.DefaultDatabase.shutdown(Databases.scala:180)
        at play.api.db.DefaultDBApi$$anonfun$shutdown$1.apply(DefaultDBApi.scala:54)
        at play.api.db.DefaultDBApi$$anonfun$shutdown$1.apply(DefaultDBApi.scala:54)
        at scala.collection.immutable.List.foreach(List.scala:381)
Caused by: com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Could not create connection to database server.
        at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:512)
        at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:105)
        at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:71)
        at play.api.db.HikariCPConnectionPool$$anonfun$1.apply(HikariCPModule.scala:58)
        at play.api.db.HikariCPConnectionPool$$anonfun$1.apply(HikariCPModule.scala:54)
        at scala.util.Try$.apply(Try.scala:192)
        at play.api.db.HikariCPConnectionPool.create(HikariCPModule.scala:54)
        at play.api.db.PooledDatabase.createDataSource(Databases.scala:199)
        at play.api.db.DefaultDatabase.dataSource$lzycompute(Databases.scala:123)
        at play.api.db.DefaultDatabase.dataSource(Databases.scala:121)
Caused by: 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)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:400)
        at com.mysql.jdbc.Util.getInstance(Util.java:383)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:958)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:937)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:872)
Caused by: java.lang.NullPointerException: null
        at com.mysql.jdbc.ConnectionImpl.getServerCharset(ConnectionImpl.java:2999)
        at com.mysql.jdbc.MysqlIO.sendConnectionAttributes(MysqlIO.java:1885)
        at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1814)
        at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1207)
        at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2249)
        at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2280)
        at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2079)
        at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:794)
        at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

E no meu navegador tem a mensagem: Failed to initialize pool: Could not create connection to database server.

solução!

Você tá usando o MySQL 8? Se estiver, faça downgrade para a versão 5, esse driver que você está usando não consegue conectar na versão 8