简体   繁体   English

使用Play框架连接到mysql db时发生异常

[英]Exception While Connecting to mysql db with play framework

I am working with PlayFramework (2.3.x) application. 我正在使用PlayFramework(2.3.x)应用程序。 I wanted to connect to a mysql db. 我想连接到mysql数据库。 Below is the configuration that I had given in application.conf : 以下是我在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. 我已经创建了数据库,并且可以与mysql控制台一起使用。

  2. I have my persistence.xml placed in my conf/META-INF. 我将persistence.xml放在conf / META-INF中。 Below is the persistence.xml 以下是persistence.xml

  3. I have root user with all privileges. 我具有所有特权的root用户。

Could anyone help me with this? 有人可以帮我吗?

According to the docs for Play 2.3.x , the correct configuration is db.default.user and not db.default.username . 根据Play 2.3.x的文档 ,正确的配置是db.default.user而不是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

您没有通过登录,如该行所示

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM