spring和mybatis整合连不上数据库

qq_44269574 2019-05-13 10:42:31
mapper接口方式的开发整合,数据库连接不上,知道的大佬告我一下
...全文
165 点赞 收藏 13
写回复
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 没办法发图片,我就复制了
回复 点赞
发动态
发帖子
Web 开发
创建于2007-09-28

5.2w+

社区成员

34.1w+

社区内容

Java Web 开发
社区公告
暂无公告