请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

连接不了数据库

老师,我在用url访问页面的时候,它报如下错误:

HTTP Status 500 - Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:

type Exception report

message Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!
### The error may exist in file [/home/work/apache-tomcat-8.0.51/webapps/o2o/WEB-INF/classes/mapper/WechatAuthDao.xml]
### The error may involve com.school.o2o.dao.WechatAuthDao.queryWechatInfoByOpenId
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:82)
org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:68)
org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:336)
org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:84)
org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62)
org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324)
org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83)
org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)
org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:77)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433)
com.sun.proxy.$Proxy19.selectOne(Unknown Source)
org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:166)
org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:82)
org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
com.sun.proxy.$Proxy31.queryWechatInfoByOpenId(Unknown Source)
com.school.o2o.service.impl.WechatAuthService.getWechatAuthByOpenId(WechatAuthService.java:35)
com.school.o2o.service.impl.WechatAuthService$$FastClassBySpringCGLIB$$3a3cef61.invoke(<generated>)
org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:669)
com.school.o2o.service.impl.WechatAuthService$$EnhancerBySpringCGLIB$$df38803.getWechatAuthByOpenId(<generated>)
com.school.o2o.web.wechat.WechatLoginController.doGet(WechatLoginController.java:67)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

接着,我就检查我的jdbc.properties文件,驱动、url、云服务器数据库的work用户的用户名和密码都是配置正确的,而且work用户的权限也是设置了可以被远程访问的(%)。也用netstat命令查看了ip的连接情况,3306是可以被外网访问的,但是连接之后出现的ip连接表是以下这样的:https://img1.sycdn.imooc.com//szimg/5aeea4f60001fd3106410580.jpg

????我的打开方式不对???

正在回答 回答被采纳积分+3

3回答

提问者 慕尼黑5582837 2018-05-06 18:26:25

https://img1.sycdn.imooc.com//szimg/5aeed84f0001330315001500.jpg
而且竟然会多冒一个33060的端口出来

0 回复 有任何疑惑可以回复我~
提问者 慕尼黑5582837 2018-05-06 18:25:01

https://img1.sycdn.imooc.com//szimg/5aeed7fc0001423815001500.jpg
本地可以连接上,但是运行项目的时候就是连不到数据库,读不了数据

0 回复 有任何疑惑可以回复我~
  • 翔仔 #1
    目前也不好定位同学的问题在哪里,我还是觉得是数据库远程连接获取不到的缘故,同学可以用你本地的程序去连接远程的数据库,用相同的配置去获取数据,调试一下,如果出现同样的问题,证明还是配置问题,可以参照以下链接逐项排查
    https://blog.csdn.net/jdfkldjlkjdl/article/details/42170749
    我猜可能是jdbc.url 后面还需要加入 &useSSL=false 试试
    回复 有任何疑惑可以回复我~ 2018-05-06 22:24:16
  • 提问者 慕尼黑5582837 回复 翔仔 #2
    老师,我这个问题前两天已经解决了。是我的数据库版本的问题,我在mysql的官网上没有找到您建议的数据库5.7版本可以下载,所以我下了8.0的版本。8.0的配置方法和5.7的很不相同,而且需要的connector版本也不同。但是我本机电脑上使用的数据库是5.7,部署到云上也不知道要修改配置文件,所以项目一直没有办法连接到云的数据库。后来我从网上好不容易才找到了5.7版本的下载地址,在云上卸载掉8.0的数据库后重新安装5.7版本的,问题就得到解决了。
    回复 有任何疑惑可以回复我~ 2018-05-08 19:48:07
  • 翔仔 回复 提问者 慕尼黑5582837 #3
    哈,这样的话建议同学使用5.7,mysql8才出来不久,并且注意:从 MySQL 5.7 升级到 MySQL 8.0 仅支持通过使用 in-place 方式进行升级,并且不支持从 MySQL 8.0 降级到 MySQL 5.7(或从某个 MySQL 8.0 版本降级到任意一个更早的 MySQL 8.0 版本)。唯一受支持的替代方案是在升级之前对数据进行备份。
    回复 有任何疑惑可以回复我~ 2018-05-08 19:55:33
翔仔 2018-05-06 16:00:19

同学好,你最好用你的配置里的帐号 ip port 从本地的mysql客户端连接到服务器试试,感觉还是没联通。

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信