spring和mybatis整合连不上数据库

qq_44269574 2019-05-13 10:42:31
mapper接口方式的开发整合,数据库连接不上,知道的大佬告我一下
...全文
325 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_44269574 2019-05-15
  • 打赏
  • 举报
回复
引用 10 楼 getdate 的回复:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> 试试
我加了destory-method出现叉号删除以后居然连接成功了,好奇怪
qq_44269574 2019-05-15
  • 打赏
  • 举报
回复
根据10楼将bean后面加了destory-method结果报错说不允许出现,然后删了之后好了,真是不解
qq_44269574 2019-05-15
  • 打赏
  • 举报
回复
引用 10 楼 getdate 的回复:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> 试试
destory-method is not allowed to appear in element bean
byds520 2019-05-14
  • 打赏
  • 举报
回复
org.apache.commons.dbcp2.BasicDataSource 这个是哪个包里的? 我记得不是这个么org.apache.commons.dbcp.BasicDataSource, 升级了?
程序魔法师 2019-05-14
  • 打赏
  • 举报
回复
数据库连接不上,往往是配置文件的问题,好好检查下配置文件
getdate 2019-05-14
  • 打赏
  • 举报
回复
把错误信息贴出来,大家更容易分析问题
对梦想的牵挂 2019-05-14
  • 打赏
  • 举报
回复
有报错信息么?
lzs19278225 2019-05-14
  • 打赏
  • 举报
回复
是username你注意你的名字
byds520 2019-05-14
  • 打赏
  • 举报
回复
配置文件中,url里的 & 符号你换成& 试试 jdbc:mysql://localhost:3306/sport?useUnicode=true&characterEncoding=utf8&autoReconnect=true
getdate 2019-05-14
  • 打赏
  • 举报
回复
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> 试试
qq_44269574 2019-05-14
  • 打赏
  • 举报
回复
引用 3 楼 getdate 的回复:
把错误信息贴出来,大家更容易分析问题
HTTP Status 500 - nested exception is org.apache.ibatis.exceptions.PersistenceException: type Exception report message nested exception is org.apache.ibatis.exceptions.PersistenceException: description The server encountered an internal error that prevented it from fulfilling this request. exception 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: Cannot create PoolableConnectionFactory (Communications link failure Last packet sent to the server was 0 ms ago.) ### The error may exist in com/itheima/mappers/Usermapper.xml ### The error may involve com.itheima.mappers.Usermapper.findUser ### The error occurred while executing a query ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Cannot create PoolableConnectionFactory (Communications link failure Last packet sent to the server was 0 ms ago.) org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77) org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446) com.sun.proxy.$Proxy14.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.$Proxy15.findUser(Unknown Source) servlet.yz.doPost(yz.java:37) javax.servlet.http.HttpServlet.service(HttpServlet.java:650) javax.servlet.http.HttpServlet.service(HttpServlet.java:731) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) root cause org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Cannot create PoolableConnectionFactory
qq_44269574 2019-05-14
  • 打赏
  • 举报
回复
引用 4 楼 weixin_44190482 的回复:
数据库连接不上,往往是配置文件的问题,好好检查下配置文件
昨天一下午搞到晚上,根据百度上说的都检查了,实在找不到问题
qq_44269574 2019-05-14
  • 打赏
  • 举报
回复
引用 2 楼 对梦想的牵挂 的回复:
有报错信息么?
HTTP Status 500 - nested exception is org.apache.ibatis.exceptions.PersistenceException: type Exception report message nested exception is org.apache.ibatis.exceptions.PersistenceException: description The server encountered an internal error that prevented it from fulfilling this request. exception 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: Cannot create PoolableConnectionFactory (Communications link failure Last packet sent to the server was 0 ms ago.) ### The error may exist in com/itheima/mappers/Usermapper.xml ### The error may involve com.itheima.mappers.Usermapper.findUser ### The error occurred while executing a query ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Cannot create PoolableConnectionFactory (Communications link failure Last packet sent to the server was 0 ms ago.) org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77) org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446) com.sun.proxy.$Proxy14.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.$Proxy15.findUser(Unknown Source) servlet.yz.doPost(yz.java:37) javax.servlet.http.HttpServlet.service(HttpServlet.java:650) javax.servlet.http.HttpServlet.service(HttpServlet.java:731) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) root cause org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Cannot create PoolableConnectionFactory 没办法发图片,我就复制了

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧