老师我发现一个问题!!

老师我发现一个问题!!

首先,我电脑没有启动MySQL,没有在cmd里登录Mysql数据库

然后

我运行程序

发现

会报异常

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

并且,页面没有输出到分类的信息

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

然后我在cmd里登录MySQL,

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

再重新刷新页面

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

这样就能显示数据了,请问报这个异常

java.sql.SQLException: Connections could not be acquired from the underlying database!

是因为我没有打开数据库吗?

但我后来把数据库退出了

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

然后再次刷新页面,并且是ctrl+F5那样去刷新,也可以正常显示页面,

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

请问这是为什么呢?请老师解答一下!


另外我还想问一下,我看到控制台中显示了一句话

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

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

请问这是什么意思呢?

是我设置的c3p0的参数错误吗?

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

但我能正常运行的呀,能成功连接数据库,并且从数据库中获取到数据的呀。

请问这是什么意思呢?

正在回答

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

14回答

同学你好,建议同学在链接数据库的url后添加&allowPublicKeyRetrieval=true,重启电脑再试试。

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

  • MasonM 提问者 #1
    厉害了老师,在连接数据库的url后添加&allowPublicKeyRetrieval=true真的管用!!!谢谢老师! 请问老师&allowPublicKeyRetrieval=true这个是什么意思呢?
    2019-05-28 12:59:06
提问者 MasonM 2019-05-28 18:38:39

我还想问一下,为啥视频中的老师的数据库url后面也没有设置这么多参数也没问题的呢?
而且,我想知道设置serverTimezone,设置时区有什么作用?

  • 老师使用的数据库是mysql 5的版本,而同学使用的mysql 8,mysql8中需要设置一些参数。另外设置时区是mysql 8的要求,如果不设置可能报错或者出现时间有误差等。同学可以去掉serverTimezone试试。祝:学习愉快~
    2019-05-28 19:09:27
  • 提问者 MasonM 回复 好帮手慕阿满 #2
    好的谢谢老师!非常感谢!
    2019-05-28 19:36:52
好帮手慕阿满 2019-05-28 17:06:38

关于同学的问题:1、香港和北京时间是一样的。2、useUnicode和characterEncoding默认为false,需要在链接数据库时具体指明,不然会出现乱码。3、allowPublicKeyRetrieval=true这里只要会用就可以了。关于密钥及加密方式等是一门更高深的学科,如果同学想专门研究数据库,可以进行这方面的具体学习。另外像同学之前的操作,如果先运行了数据库,然后再运行程序,即使不加allowPublicKeyRetrieval=true也是可以的。

祝:学习愉快~

  • 提问者 MasonM #1
    老师,我还想问一个问题,这里设置的useUnicode和characterEncoding,这个设置字符集是什么意思呢?数据库里面创建库和创建表的时候不是已经设置字符集了吗,那这里的设置字符集有什么用?
    2019-05-28 17:13:25
  • 好帮手慕阿满 回复 提问者 MasonM #2
    同学你好,这里是指程序在和mysql中进行交互时的字符集,如果不统一一下,很可能在使用程序向数据库中写入数据时或者使用程序从数据库中读取数据时初夏乱码。祝:学习愉快~
    2019-05-28 18:26:48
  • 提问者 MasonM 回复 好帮手慕阿满 #3
    噢~就是说,useUnicode和characterEncoding是用来规定从Java程序写入到数据库的数据的字符集吗?
    2019-05-28 18:30:07
好帮手慕阿满 2019-05-28 15:27:07

同学你好,关于数据库连接的url中,serverTimezone=Hongkong是设置时区,使用的是香港时间。

useUnicode=true&characterEncoding=utf8通常是一起写。useUnicode是否使用Unicode字符集,如果参数characterEncoding设置utf8时,参数值需要设置为true。characterEncoding=utf8是设置字符集编码方式。

allowPublicKeyRetrieval=true,这个是mysql8中,mysql服务器的默认身份验证方法是SHA256, Connector/J连接属性中没有一个允许公共密钥检索和服务器安全密钥文件被设置,则身份验证失败,出现了传递连接异常,无法检索公共密钥,设置allowPublicKeyRetrieval=true后,可以检索公共密钥。

同学知道这几个常用的url设置即可。

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

  • 提问者 MasonM #1
    老师,那用serverTimezone设置时区的话,香港跟北京时间是不是效果一样的呀?
    2019-05-28 15:30:48
  • 提问者 MasonM #2
    useUnicode=true&characterEncoding=utf8 如果不这样设置的话,默认是怎样的?
    2019-05-28 15:32:48
  • 提问者 MasonM #3
    allowPublicKeyRetrieval=true 关于这个设置,里面说连接属性,什么密钥,以及SHA256都是什么呀?为啥课程不介绍一下呢? 为什么设置了这个之后,我就能直接运行项目就可以访问数据库呢,不会像之前那样报错了
    2019-05-28 15:35:40
提问者 MasonM 2019-05-28 13:01:17
<property name="jdbcUrl">jdbc:mysql:///shop?useSSL=false&amp;serverTimezone=Hongkong&amp;useUnicode=true&amp;characterEncoding=utf-8&amp;allowPublicKeyRetrieval=true</property>

老师我现在的数据库url是这么长,我想知道,后面有些设置是什么意思?

如:

serverTimezone=Hongkong

useUnicode=true

characterEncoding=utf-8

allowPublicKeyRetrieval=true

这些都是什么意思呢?

以及还有没有别的常用的参数设置介绍一下呀?

提问者 MasonM 2019-05-27 20:02:57

java.sql.SQLException: Connections could not be acquired from the underlying database!

27-May-2019 19:55:30.518 警告 [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1] com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@a510ed9 -- 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.SQLNonTransientConnectionException: Public Key Retrieval is not allowed

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)

at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)

at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)

at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)

at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)

at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)

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)


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.mason.utils.JDBCUtils.getConnection(JDBCUtils.java:24)

at com.mason.dao.impl.CategoryDaoImpl.findAll(CategoryDaoImpl.java:23)

at com.mason.service.impl.CategoryServiceImpl.findAll(CategoryServiceImpl.java:16)

at com.mason.web.action.CategoryServlet.findAll(CategoryServlet.java:42)

at com.mason.web.action.CategoryServlet.doGet(CategoryServlet.java:26)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:635)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)

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:493)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)

at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:660)

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:798)

at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)

at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806)

at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)

at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

at java.lang.Thread.run(Thread.java:748)

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

27-May-2019 19:55:30.521 警告 [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0] com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@612d0ddf -- 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.SQLNonTransientConnectionException: Public Key Retrieval is not allowed

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)

at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)

at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)

at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)

at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)

at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)

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)


提问者 MasonM 2019-05-27 20:01:23

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.mason.utils.JDBCUtils.getConnection(JDBCUtils.java:24)

at com.mason.dao.impl.CategoryDaoImpl.findAll(CategoryDaoImpl.java:23)

at com.mason.service.impl.CategoryServiceImpl.findAll(CategoryServiceImpl.java:16)

at com.mason.web.action.CategoryServlet.findAll(CategoryServlet.java:42)

at com.mason.web.action.CategoryServlet.doGet(CategoryServlet.java:26)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:635)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)

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:493)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)

at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:660)

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:798)

at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)

at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806)

at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)

at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

at java.lang.Thread.run(Thread.java:748)

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

CategoryServlet的findAll方法执行了

CategoryService的findAll方法执行了

CategoryDao的findAll方法执行了...

27-May-2019 19:55:30.518 警告 [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2] com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@e0f7dee -- 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.SQLNonTransientConnectionException: Public Key Retrieval is not allowed

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)

at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)

at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)

at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)

at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)

at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)

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!

27-May-2019 19:55:30.518 警告 [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1] com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@a510ed9 -- 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.SQLNonTransientConnectionException: Public Key Retrieval is not allowed

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)

at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)

at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)

at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)

at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)

at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)

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)


提问者 MasonM 2019-05-27 19:59:53

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

27-May-2019 19:54:21.653 警告 [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1] com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@445b38a1 -- 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.SQLNonTransientConnectionException: Public Key Retrieval is not allowed

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)

at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)

at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)

at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)

at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)

at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)

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)


27-May-2019 19:54:21.653 警告 [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2] com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@39480b06 -- 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.SQLNonTransientConnectionException: Public Key Retrieval is not allowed

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)

at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)

at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)

at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)

at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)

at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)

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)


27-May-2019 19:54:21.653 警告 [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0] com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@4e98c4c2 -- 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.SQLNonTransientConnectionException: Public Key Retrieval is not allowed

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)

at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)

at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)

at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)

at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)

at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)

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)


提问者 MasonM 2019-05-27 19:58:52

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

我这里已经是默认自动启动数据库的,并且已经在数据库服务已经在运行了,还是不行

  • 提问者 MasonM #1
    我把全部报错贴出来了,请老师帮我排查一下谢谢!!!
    2019-05-27 20:03:21
吃吃吃鱼的猫 2019-05-27 19:17:12

同学你好,老师根据经验猜测同学的MySQ数据库在开机时是不会自动启动的~

现在大部分数据库是默认开机自启的,同学可以按照如下步骤进行数据库开机自启操作:

我的电脑-->鼠标右键-->管理-->服务和应用程序-->服务-->找到mysql-->鼠标右键-->属性-->把启动类型改为自动

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

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

  • 提问者 MasonM #1
    老师我的数据库也是默认自动开机启动的哟,你看看我的新回答,但问题还是这样,我重启电脑之后,再次运行程序,也是连接不了数据库,我去查看MySQL的服务,是已经在运行了
    2019-05-27 19:56:57
  • 提问者 MasonM #2
    依然是我需要手动在cmd里登录一次MySQL才能正常获得连接,程序才能获取到数据库中的数据
    2019-05-27 20:05:13
吃吃吃鱼的猫 2019-05-27 11:35:49

同学你好,这可能是由于电脑配置导致项目启动时间过长,同学再次重新启动即可。

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

  • 提问者 MasonM #1
    老师,我发现我这个问题,是这样的: 就是我重启电脑之后,打开IDEA,运行项目,就会这样子出现java.sql.SQLException: Connections could not be acquired from the underlying database!报错,就算我把项目重新启动很多次也是这样子的
    2019-05-27 18:34:00
  • 提问者 MasonM #2
    然后,只要我在cmd里登录一次MySQL,这个问题马上能解决!就不会报错,很顺利就能把分类页面信息显示出来,请问这是什么情况呢?
    2019-05-27 18:36:03
  • 提问者 MasonM #3
    我发现登录功能也是这样子的,就是,我重启电脑之后,马上打开IDEA,运行项目,然后测试登录功能,也是无法获取到数据库连接,然后我也是在cmd里登录一次MySQL,这个问题马上能解决!
    2019-05-27 18:41:33
吃吃吃鱼的猫 2019-05-27 11:19:25

同学你好,

现在还没有使用远程访问权限哦~所以错误和这个是无关的~

具体是哪个问题,要看具体的代码和配置呢,问题有时无法一下找出来,需要一点一点排除。这里老师为同学提供一种错误的排查方法~

同学这里的原因可能是因为运行时间过长,期间没有能连接到数据库~

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

  • 提问者 MasonM #1
    运行时间过长,期间没有能连接到数据库是什么意思呢?怎样解决呢?
    2019-05-27 11:20:27
吃吃吃鱼的猫 2019-05-27 10:57:29

同学你好,可能有如下原因:

1、驱动配置有误

2、数据库连接地址有误
3、密码或帐号有误

4、数据库未启动或无权访问

5、项目未引入对应的驱动jar包mysql-connector-java-5.1.6-bin.jar

6、mysql root没有远程访问的权限,需要增加权限

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

  • 提问者 MasonM #1
    老师,我怎样判断我是哪个问题呢,但我能确定,数据库账号密码没错,以及引入的驱动jar是正确的
    2019-05-27 11:03:21
  • 提问者 MasonM #2
    而且我也是本机访问数据库呀,跟远程访问权限有关系吗
    2019-05-27 11:08:03
吃吃吃鱼的猫 2019-05-27 10:46:35

同学你好,

1、java程序内部是会自动连接数据库的。出现下面的异常信息,可能是因为运行时间过长,期间没有能连接到数据库,所以,报如下错误,与同学运行之前通过cmd登录数据库是无关的。

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

2、如下图所示,提示信息表明数据库驱动com.mysql.jdbc.driver已被弃用。新的驱动程序类是com.mysql.cj.jdbc.driver。驱动程序通过SPI自动注册,通常不需要手动加载驱动程序类。

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

所以,按照提示更改driverClass的配置 .com.mysql.jdbc.Driver  改为  com.mysql.cj.jdbc.Driver。

因为内部自动注册,所以,不更改也可以自动获取加载,仍能连接数据库哦~

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


  • 提问者 MasonM #1
    老师,那么我想知道,如果出现问题1的报异常无法获得链接的情况,怎样解决?
    2019-05-27 10:52:44
问题已解决,确定采纳
还有疑问,暂不采纳

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

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

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

在线咨询

领取优惠

免费试听

领取大纲

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