关于SSH2的访问数据库问题。

asdfasdfffs324 2013-09-26 10:03:55
public int findNumByCondition(Map<String,String> map) throws Exception {
String hql="";
hql += "from EAqInsAfamanageillegal536 where isdeleted = 0";
hql += createHql(map);
return this.findWhereCount(hql);
}
本人使用此方法、map为传递的所有参数,我另写了一个方法进行动态拼接。 现在出现的问题是: 对有些参数调用没有问题。而有些却报了如下的错误:

org.hibernate.hql.ast.QuerySyntaxException: unexpected token: 9 near line 1, column 130 [from com.Achilles.entity.common.EAqInsFandmanageillegal534 where isdeleted = 0 and reportyear =2013 and to_number(reportmonth) =09 and reporttype =1 and QCmnOperatepoint20.operatepointid =153]

我的SQL执行没有问题; to_number(reportmonth)==01 或者02等等 没有问题,唯独09 或者08 执行此查询的时候报错。请高手指点!!!本人使用的是mysql数据库
...全文
103 2 打赏 收藏 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zyrobert 2013-09-26
  • 打赏
  • 举报
回复
语法错 但是我也看不出来哪里错 帮顶!
asdfasdfffs324 2013-09-26
  • 打赏
  • 举报
回复
这是我的动态评价方法,没有问题 : public String createHql(Map<String,String> map){ String hql=""; if(!"".equals(map.get("year")) && map.get("year") != null){ hql += " and reportyear ="+map.get("year"); } if(!"".equals(map.get("month")) && map.get("month") != null){ hql += " and to_number(reportmonth) ="+map.get("month"); } if(!"".equals(map.get("leimonth")) && map.get("leimonth") != null){ hql += " and to_number(reportmonth) >="+map.get("leimonth"); } if(!"".equals(map.get("reporttype")) && map.get("reporttype") != null){ hql += " and reporttype ="+map.get("reporttype"); } if(!"".equals(map.get("isreport")) && map.get("isreport") != null){ hql += " and isreport ="+map.get("isreport"); } if(!"".equals(map.get("reportstatus")) && map.get("reportstatus") != null){ hql += " and reportstatus ="+map.get("reportstatus");//是否存盘或者上报 } if(!"".equals(map.get("checkisreport")) && map.get("checkisreport") != null){ hql += " and reportstatus >=0 ";//是否存盘或者上报 } if(!"".equals(map.get("userid")) && map.get("userid") != null){ hql += " and UUsrUser36.userid ="+map.get("userid"); } if(!"".equals(map.get("departmentid")) && map.get("departmentid") != null){ hql += " and QCmnDepartment23.departmentid ="+map.get("departmentid"); } if(!"".equals(map.get("operpointid")) && map.get("operpointid") != null){ hql += " and QCmnOperatepoint20.operatepointid ="+map.get("operpointid"); } if(!"".equals(map.get("notJuoperpointid")) && map.get("notJuoperpointid") != null){ hql += " and QCmnOperatepoint20.operatepointid != 153 "; } if(!"".equals(map.get("isaggregateblock")) && map.get("isaggregateblock") != null){ hql += " and isaggregateblock="+map.get("isaggregateblock"); } if(!"".equals(map.get("reportDateStart")) && map.get("reportDateStart") != null){ hql += " and reportdate>=to_date('"+map.get("reportDateStart")+"','yyyy-mm-dd')"; } if(!"".equals(map.get("reportDateStop")) && map.get("reportDateStop") != null){ hql += " and reportdate<=to_date('"+map.get("reportDateStop")+"','yyyy-mm-dd')"; } if(!"".equals(map.get("order")) && map.get("order") != null){ hql+=" order by reportdate desc"; } if(!"".equals(map.get("monthOrder")) && map.get("monthOrder") != null){ hql+=" order by to_number(reportmonth) desc"; } return hql; }

62,620

社区成员

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

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