李振海
2017-12-15 22:42:54
完
mybatis多表查询问题
WechatUser currentWechatUser = wechatUserDao.selectByPrimaryKey(wechatUserId); Business currentBusiness = businessDao.selectByPrimaryKey(businessId); Weishangqiang currentWeishangqiang = weishangqiangDao.selectByPrimaryKey(businessWeishangqiangDao.selectByBusinessId(currentBusiness.getId()).getWeishangqiangId()); List<WeishangqiangContent> currentWeishangqiangContentList = weishangqiangContentDao.selectByWeishangqiangIdInOrderCreateTimeAsc(currentWeishangqiang.getId(), lastTime); List<WeishangqiangContentResult> currentWeishangqiangContentResultList = new ArrayList<WeishangqiangContentResult>(); int maxId = 0; int length = currentWeishangqiangContentList.size(); int start = 0; if (length > 10) { start = length - 10; } for (int i = start; i < length; i++) { // for (WeishangqiangContent weishangqiangContent : currentWeishangqiangContentList) { WeishangqiangContent weishangqiangContent = currentWeishangqiangContentList.get(i); if (maxId < weishangqiangContent.getId()) { maxId = weishangqiangContent.getId(); } WeishangqiangContentResult weishangqiangContentResult = new WeishangqiangContentResult(); weishangqiangContentResult.setId(weishangqiangContent.getId()); weishangqiangContentResult.setWechatUser(wechatUserDao.selectByPrimaryKey(weishangqiangContent.getWechatUserId())); weishangqiangContentResult.setWeishangqiangId(weishangqiangContent.getWeishangqiangId()); weishangqiangContentResult.setType(weishangqiangContent.getType()); if (weishangqiangContent.getType() == 1) { weishangqiangContentResult.setOwnScreen(ownScreenDao.selectByPrimaryKey(weishangqiangContent.getOwnScreenId())); if (weishangqiangContent.getImgUrl() != null && !"".equals(weishangqiangContent.getImgUrl())){ weishangqiangContentResult.setImgUrl(weishangqiangContent.getImgUrl().split(",")); } weishangqiangContentResult.setVideoUrl(weishangqiangContent.getVideoUrl()); } else if (weishangqiangContent.getType() == 2) { Dashang dashang = dashangDao.selectByPrimaryKey(weishangqiangContent.getDashangId()); DashangTar dashangTar = dashangTarDao.selectByPrimaryKey(weishangqiangContent.getDashangTarId()); weishangqiangContentResult.setDashang(dashang); weishangqiangContentResult.setDashangTar(dashangTar); } else if (weishangqiangContent.getType() == 3) { weishangqiangContentResult.setGift(giftMapper.selectByPrimaryKey(weishangqiangContent.getOwnScreenId())); weishangqiangContentResult.setToWechatUser(wechatUserDao.selectByPrimaryKey(weishangqiangContent.getToWechatUserId())); } else if (weishangqiangContent.getType() == ActionConsts.RED_PACKAGE_TYPE) { weishangqiangContentResult.setRedPackage(redPackagesMapper.selectByPrimaryKey(weishangqiangContent.getContent())); } else if (weishangqiangContent.getType() == ActionConsts.EXPRESS_LOVE_TYPE) { weishangqiangContentResult.setImgUrl(weishangqiangContent.getImgUrl().split(",")); weishangqiangContentResult.setVideoUrl(weishangqiangContent.getVideoUrl()); ExpressLove el = expressLoveMapper.selectByPrimaryKey(weishangqiangContent.getOwnScreenId()); String name = ElThemeConsts.THEMEMAP.get(weishangqiangContent.getThemeId() + ""); el.setName(name); weishangqiangContentResult.setExpressLove(el); weishangqiangContentResult.setToWechatUser(wechatUserDao.selectByPrimaryKey(weishangqiangContent.getToWechatUserId())); } weishangqiangContentResult.setContent(weishangqiangContent.getContent()); weishangqiangContentResult.setCreateTime(new SimpleDateFormat("MM-dd HH:mm").format(weishangqiangContent.getCreateTime())); currentWeishangqiangContentResultList.add(weishangqiangContentResult); } BusinessWechatUser businessWechatUser = new BusinessWechatUser(); businessWechatUser.setBusinessId(businessId); businessWechatUser.setWechatUserId(wechatUserId); businessWechatUser = businessWechatUserDao.selectByBusinessId(businessWechatUser); List<Dashang> dashangList = dashangDao.selectListByWeishangqiangId(currentWeishangqiang.getId()); List<DashangTar> dashangTarList = dashangTarDao.selectList(); List<Gift> giftList = giftMapper.selectListByWeishangqiangId(currentWeishangqiang.getId()); int currentWeishangqiangAccessAccount = Integer.valueOf(currentWeishangqiang.getAccessAccount()); currentWeishangqiang.setAccessAccount(String.valueOf(currentWeishangqiangAccessAccount + 1)); weishangqiangDao.updateByPrimaryKeySelective(currentWeishangqiang); List<String> listWechatId = orderDao.getPayMostTopUser(10, businessId); if (listWechatId.contains(wechatUserId)) { int haobang = listWechatId.indexOf(wechatUserId + "") + 1; model.addAttribute("haobang", haobang); } else { model.addAttribute("haobang", 11); } if (currentWeishangqiangContentList.size() == 0) { Integer value = weishangqiangContentDao.selectMaxId(currentWeishangqiang.getId()); maxId = value == null ? 0 : value; } model.addAttribute("maxId", maxId); model.addAttribute("timestamp", DateUtil.getCurrentTime()); model.addAttribute("currentWechatUser", currentWechatUser); model.addAttribute("currentBusiness", currentBusiness); model.addAttribute("businessWechatUser", businessWechatUser); model.addAttribute("currentWeishangqiang", currentWeishangqiang); model.addAttribute("currentWeishangqiangContentResultList", JSON.toJSONString(currentWeishangqiangContentResultList)); model.addAttribute("dashangList", JSON.toJSONString(dashangList)); model.addAttribute("dashangTarList", JSON.toJSONString(dashangTarList)); model.addAttribute("giftList", JSON.toJSONString(giftList)); model.addAttribute("expressLoveList", JSON.toJSONString(expressLoveMapper.getExpressListByWeishangqiangId(currentWeishangqiang.getId()))); model.addAttribute("shortUrl", shortUrlMapper.selectByPrimaryKey(businessId).getShorturl()); List<Map<String,Object>> list = orderDao.payMostWechatUser(businessId); if (list.size() > 0) { model.addAttribute("payMost", list.get(0)); } else { model.addAttribute("payMost", null); } return "/customer/weishangqiang"; }
这是公司以前人写的代码,昨天晚上项目报
Could not get JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection, message from server: "Too many connections"] with root cause com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection, message from server: "Too many connections"
请大神看看和这块代码关系大吗
评论
所有回答列表(2)
码农_老王 LV10
2017年12月16日
产生这种问题的原因是:
连接数超过了 MySQL 设置的值,与 max_connections 和 wait_timeout 都有关系。wait_timeout 的值越大,连接的空闲等待就越长,这样就会造成当前连接数越大。
解决方法:
修改MySQL配置文件/etc/my.cnf,设置成max_connections=1000,wait_timeout=5。如果没有此项设置可以自行添加,修改后重启MySQL服务即可。要不经常性报此错误,则要对服务器作整体性能优化。
总结,解决问题的最终方法:
1.修改配置文件/etc/my.cnf,调整连接参数
2.检查程序代码,对于没有关闭的链接及时进行关闭
评论(1)
最佳答案
- 等 最代码怎么获取牛币啊?
- 完 谁来告诉我最代码上线的时间,答对者给5牛币,先来先得
- 等 牛友们,大家好,你们做程序员多久了?现在还好吗?
- 完 在微信打开的页面里进行app下载
- 等 最代码2014年欢乐聚声会
- 完 mysql如何查询表数据并且对3个字段降序的SQL?
- 完 最代码牛币机制改革
- 完 成功的在bae上使用了自定义运行环境 jetty+nginx的组合,大家对jetty+nginx优化有哪些心得?
- 完 进来分享一下各位牛牛是如何加入最代码大家庭的?
- 等 为什么java BufferedImage类处理大图直接抛出内存溢出的异常?
- 等 最代码是否开发手机app客户端?
- 完 java程序员学习哪些java的技术?java有哪些框架?都能做哪方面的开发?
- 等 php格式网页文件怎么运行?
- 等 Java volatile值获取的问题
- 等 前端vue,拦截了登录后台后,返回的token,requests拦截token,但是发送请求的时候,就出现跨越异常
- 等 大专本科计算机科班怎么找到Java工作?
- 等 eclipse怎么把三个java swing游戏项目合成一个项目?
- 完 伙伴们,大家都有什么好的解压方式么,分享一下~
- 完 三四线城市,6、7k,运维工作,索然无味,想去辞职上培训,各位牛牛有什么建议嘛
- 等 jsp页面输入中文变成问号
- 等 JPA在线上运行一段时间后报错Caused by: java.lang.IncompatibleClassChangeError: null
- 等 PHP 这个规则用preg_match_all怎么写
- 等 大佬们,有没有知道Alfresco如何配置LDAP登录呢?
- 等 php的install目录是框架带的吗?
相关问答
- 完 mybatis查询抛出异常
- 等 Mybatis多表查询的问题
- 完 mybatis抛出异常JDBC requires that the JdbcType must be specified for all nullable parameters.
- 完 mybatis为什么抛出Mapped Statements collection does not contain value for xxx的异常?
- 等 Mybatis开发中分页插件怎么用?
- 完 spring整合mybatis后的声明事务和注解事务有什么区别?
- 等 mybatis批量插入数据如何获得每条记录的主键?
- 等 mybatis一对多关联为什么查询不到数据?
- 等 mybatis association查询怎么使用?
- 等 mybatis中的model继承问题
- 等 jdbc与mybatis有什么区别?
- 等 mybatis可以写max函数吗?