1

I am working with PlayFramework (2.3.x) application. I wanted to connect to a mysql db. Below is the configuration that I had given in application.conf:

db.default.driver="com.mysql.jdbc.Driver"
db.default.url="jdbc:mysql://localhost/mydb"
db.default.jndiName=DefaultDS
db.default.username=root
db.default.password=root
db.default.logStatements=true
jpa.default=defaultPersistenceUnitName

When I run the application I am getting the following exception

Oops, cannot start the server.
Configuration error: Configuration error[Cannot connect to database [default]]
    at play.api.Configuration$.play$api$Configuration$$configError(Configuration.scala:94)
    at play.api.Configuration.reportError(Configuration.scala:743)
    at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:247)
    at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:238)
    at scala.collection.immutable.List.map(List.scala:273)
    at play.api.db.BoneCPPlugin.onStart(DB.scala:238)
    at play.api.Play$$anonfun$start$1$$anonfun$apply$mcV$sp$1.apply(Play.scala:91)
    at play.api.Play$$anonfun$start$1$$anonfun$apply$mcV$sp$1.apply(Play.scala:91)
    at scala.collection.immutable.List.foreach(List.scala:381)
    at play.api.Play$$anonfun$start$1.apply$mcV$sp(Play.scala:91)
    at play.api.Play$$anonfun$start$1.apply(Play.scala:91)
    at play.api.Play$$anonfun$start$1.apply(Play.scala:91)
    at play.utils.Threads$.withContextClassLoader(Threads.scala:21)
    at play.api.Play$.start(Play.scala:90)
    at play.core.StaticApplication.<init>(ApplicationProvider.scala:55)
    at play.core.server.NettyServer$.createServer(NettyServer.scala:253)
    at play.core.server.NettyServer$$anonfun$main$3.apply(NettyServer.scala:289)
    at play.core.server.NettyServer$$anonfun$main$3.apply(NettyServer.scala:284)
    at scala.Option.map(Option.scala:146)
    at play.core.server.NettyServer$.main(NettyServer.scala:284)
    at play.core.server.NettyServer.main(NettyServer.scala)
Caused by: java.sql.SQLException: Access denied for user ''@'localhost' (using password: YES)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3847)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3783)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:871)
    at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1665)
    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)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:400)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at com.jolbox.bonecp.BoneCP.obtainRawInternalConnection(BoneCP.java:363)
    at com.jolbox.bonecp.BoneCP.<init>(BoneCP.java:416)
    at com.jolbox.bonecp.BoneCPDataSource.getConnection(BoneCPDataSource.java:120)
    at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:240)
    ... 18 more
  1. I have my db created and I am able to use with mysql console.

  2. I have my persistence.xml placed in my conf/META-INF. Below is the persistence.xml

  3. I have root user with all privileges.

Could anyone help me with this?

0

2 Answers 2

1

According to the docs for Play 2.3.x, the correct configuration is db.default.user and not db.default.username. That is probably the cause of the exception. So change your configuration to:

db.default.driver="com.mysql.jdbc.Driver"
db.default.url="jdbc:mysql://localhost/mydb"
db.default.jndiName=DefaultDS
db.default.user=root
db.default.password=root
db.default.logStatements=true
jpa.default=defaultPersistenceUnitName
Sign up to request clarification or add additional context in comments.

1 Comment

yup. I noticed and corrected it. Its working fine. Thanks.
0

You are not passing a login, as indicated by the line

Caused by: java.sql.SQLException: Access denied for user ''@'localhost' (using password: YES)

1 Comment

db.default.username=root db.default.password=root DB credentials are present in config .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.