请老师解答一下,我的数据库连接不上请问是为什么,附上错误信息和连接池配置

请老师解答一下,我的数据库连接不上请问是为什么,附上错误信息和连接池配置

四月 03, 2020 10:56:16 上午 com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run
警告: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@2bac991b -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: Client does not support authentication protocol requested by server; consider upgrading MySQL client
 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:921)
 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870)
 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:812)
 at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3269)
 at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1182)
 at com.mysql.jdbc.Connection.createNewIO(Connection.java:2670)
 at com.mysql.jdbc.Connection.<init>(Connection.java:1531)
 at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
 at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
 at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
 at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
 at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
 at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
 at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
 at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
 at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

java.sql.SQLException: Connections could not be acquired from the underlying database!
 at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
 at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529)
 at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
 at com.utils.JDBCUtils.getConnection(JDBCUtils.java:24)
 at com.Dao.UserDao.login(UserDao.java:18)
 at com.Service.UserServiceImp.login(UserServiceImp.java:11)
 at com.Servlet.LoginServlet.doGet(LoginServlet.java:30)
 at com.Servlet.LoginServlet.doPost(LoginServlet.java:45)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
 at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:543)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
 at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:688)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
 at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:609)
 at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
 at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:818)
 at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1623)
 at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
 at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
 at java.lang.Thread.run(Unknown Source)
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
 at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
 at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
 at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
 at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
 ... 30 more



<?xml version="1.0" encoding="UTF-8"?>
<c3p0-config>
  <default-config>
    <property name="driverClass">com.mysql.jdbc.Driver</property>
    <property name="jdbcUrl">jdbc:mysql:///message_board</property>
    <property name="user">root</property>
    <property name="password">1234</property>
  </default-config>
</c3p0-config>

用户密码都对,我查了下可能需要远程登陆权限,但是grant all privileges  on *.* to root@'%' identified by "1234";这行命令报错,而且没有password的字段

正在回答

登陆购买课程后可参与讨论,去登陆

2回答

同学你好,根据报错信息,链接数据库的时区不正确,具体如下:

http://img1.sycdn.imooc.com/climg/5e86f91109744a1605470076.jpg

需要在连接数据库后面设置下时区和数据库的字符集编码等参数。

如:

jdbc:mysql:///message_board?useSSL=false&serverTimezone=Hongkong&useUnicode=true&CharacterEncoding=utf-8

ps:xml中记得&要写成&amp;

如果我的回答解决了你的疑惑,请采纳!祝学习愉快!

  • 咖啡灌不醉 提问者 #1
    谢谢老师答疑,最后将url配置成如下形式才连接成功的 jdbc:mysql:///message_board?CharacterEncoding=UTF-8&amp;useSSL=false&amp;serverTimezone=GMT%2B8&amp;allowPublicKeyRetrieval=TRUE
    2020-04-03 17:40:51
好帮手慕小脸 2020-04-03 14:43:07

同学你好,可能是jar包版本不一致造成。这里同学可以先使用cmd查看是否可以访问数据?然后再确认数据库的版本和jar包的版本是否一致。

如果不一致,将其更改一致即可。

祝学习愉快~

  • 提问者 咖啡灌不醉 #1
    您好,我在cmd中可以正常访问数据,jar包做了检查。因为我下载的mysql和workbench都是8.0.18版本的,因此也对jar包做了更新。同时对连接池里的driverclass也做了更改为com.mysql.cj.jdbc.Driver。访问权限也都设置好了。但仍然无法连接到数据库。我的是windows版本,数据库jar包下载时操作平台选的是Platform Independent。报错仍然是: Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: java.sql.SQLException: The server time zone value '?й???????' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support. The server time zone value '?й???????' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support. Connections could not be acquired from the underlying database! A ResourcePool could not acquire a resource from its primary factory or source.
    2020-04-03 16:22:14
  • 提问者 咖啡灌不醉 #2
    由于没有windows操作系统的版本所以选择了Platform Independent
    2020-04-03 16:24:16
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师