大虾们,快点过来瞅瞅,搞的头都大了.关于ORA-01858的问题.在线等

wanjunis 2012-04-06 03:09:36
这是代码:
public Page pageCount(Page page,String userName,String startDate,String endDate,String deptid){
String sql="select sum(cnt) from (select count(*) as cnt from t_humn_leave where DELFLAG=0 and USERID in (select ID from T_APP_USER where NAME like ? ) and startDate between ? and ? " +
" union select count(*) from t_humn_overtime where DELFLAG=0 and USERID in (select ID from T_APP_USER where NAME like ? ) and startDate between ? and ? " +
" union select count(*) from t_humn_training where DELFLAG=0 and USERID in (select ID from T_APP_USER where NAME like ? ) and startDate between ? and ? )";
Query queryCount= getSession().createSQLQuery(sql);
queryCount.setParameter(0, "'%"+userName+"%'");
queryCount.setParameter(1, "to_date("+startDate+", 'yyyy-mm-dd hh24:mi:ss')");
queryCount.setParameter(2, "to_date("+endDate+", 'yyyy-mm-dd hh24:mi:ss')");
queryCount.setParameter(3, "'%"+userName+"%'");
queryCount.setParameter(4, "to_date("+startDate+", 'yyyy-mm-dd hh24:mi:ss')");
queryCount.setParameter(5, "to_date("+endDate+", 'yyyy-mm-dd hh24:mi:ss')");
queryCount.setParameter(6, "'%"+userName+"%'");
queryCount.setParameter(7, "to_date("+startDate+", 'yyyy-mm-dd hh24:mi:ss')");
queryCount.setParameter(8, "to_date("+endDate+", 'yyyy-mm-dd hh24:mi:ss')");
Object count =queryCount.uniqueResult();
//Query query = getSession().createSQLQuery(sql).addEntity(entityClass);
//query.list();
String sql1="select '请假',DEPTID,USERID,STARTDATE,ENDDATE,RECORDER,REMARK,ID from t_humn_leave where DELFLAG=0 and USERID in (select ID from T_APP_USER where NAME like ? ) and startDate between ? and ? " +
"union select '加班',DEPTID,USERID,startDate,endDate,RECORDER,REMARK,ID from t_humn_overtime where DELFLAG=0 and USERID in (select ID from T_APP_USER where NAME like ? ) and startDate between ? and ? " +
" union select '外出培训',DEPTID,USERID,startDate,endDate,RECORDER,REMARK,ID from t_humn_training where DELFLAG=0 and USERID in (select ID from T_APP_USER where NAME like ? ) and startDate between ? and ? ";
Query query=getSession().createSQLQuery(sql1);
query.setParameter(0, "%"+userName+"%");
query.setParameter(1, "to_date('"+startDate+"', 'yyyy-mm-dd')");
query.setParameter(2, "to_date('"+endDate+"', 'yyyy-mm-dd')");
query.setParameter(3, "%"+userName+"%");
query.setParameter(4, "to_date('"+startDate+"', 'yyyy-mm-dd')");
query.setParameter(5, "to_date('"+endDate+"', 'yyyy-mm-dd')");
query.setParameter(6, "%"+userName+"%");
query.setParameter(7, "to_date('"+startDate+"', 'yyyy-mm-dd')");
query.setParameter(8, "to_date('"+endDate+"', 'yyyy-mm-dd')");
System.out.println("三表总记录条数"+count);
List list = query.list();
page.setResult(list);
page.setTotalCount(((Number)count).longValue());
return page;
}
这是错误:
2012-04-06 15:04:13,953 [http-8686-6] WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 1858, SQLState: 22008
2012-04-06 15:04:13,953 [http-8686-6] ERROR [org.hibernate.util.JDBCExceptionReporter] - ORA-01858: 在要求输入数字处找到非数字字符
2012-04-06 15:05:02,109 [http-8686-6] ERROR [500.jsp] - could not execute query
org.hibernate.exception.DataException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:102)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2452)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2192)
at org.hibernate.loader.Loader.list(Loader.java:2187)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:316)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1832)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:179)
at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:859)
at com.pengtu.dao.human.LeaveDao.pageCount(LeaveDao.java:35)
at com.pengtu.service.human.LeaveOvertimeManager.getleaveOvertimeTrainingMap(LeaveOvertimeManager.java:331)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:688)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621)
at com.pengtu.web.human.LeaveOvertimeAction.personnel(LeaveOvertimeAction.java:122)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)

上面说:在要求输入数字处找到非数字字符 但是我sql语句中的占位符根本就没有用到数字的地方都是String类型的.难道是Date哪里的问题? 帮忙看看啊. 头疼了 我休息会.谢了
...全文
895 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
chengjiang008 2013-06-27
  • 打赏
  • 举报
回复
不错,也解决了我的问题,谢谢了【flagiris】
wanjunis 2012-04-06
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]

像这种to_date的sql函数是不能当字符串传进?里的,它会当做普通的to_date字符串。

要改成
where NAME like ? and startDate between to_date(?, 'yyyy-mm-dd hh24:mi:ss') and to_date(?, 'yyyy-mm-dd hh24:mi:ss')
[/Quote]

不好意思了.以为大虾都没抓了.不过还是感谢你哈.给了我答案.下次给你分吧.
菖蒲老先生 2012-04-06
  • 打赏
  • 举报
回复
像这种to_date的sql函数是不能当字符串传进?里的,它会当做普通的to_date字符串。

要改成
where NAME like ? and startDate between to_date(?, 'yyyy-mm-dd hh24:mi:ss') and to_date(?, 'yyyy-mm-dd hh24:mi:ss')
wanjunis 2012-04-06
  • 打赏
  • 举报
回复
大虾们都被捉走了吗?我自己解决了.不知道是不是to_date()因为无法用占位符传过去还是其他什么的.我把to_date()放到sql语句中就好了. 感谢quhuafeng521的回帖.3Q虽然慢了一步但是分还是给你吧. 下面是代码
String sql="select sum(cnt) from (select count(*) as cnt from t_humn_leave where DELFLAG=0 and USERID in (select ID from T_APP_USER where NAME like ? ) and startDate between to_date(?, 'yyyy-mm-dd') and to_date(?, 'yyyy-mm-dd') " +
" union select count(*) from t_humn_overtime where DELFLAG=0 and USERID in (select ID from T_APP_USER where NAME like ? ) and startDate between to_date(?, 'yyyy-mm-dd') and to_date(?, 'yyyy-mm-dd') " +
" union select count(*) from t_humn_training where DELFLAG=0 and USERID in (select ID from T_APP_USER where NAME like ? ) and startDate between to_date(?, 'yyyy-mm-dd') and to_date(?, 'yyyy-mm-dd') )";
Query queryCount= getSession().createSQLQuery(sql);
queryCount.setParameter(0, "'%"+userName+"%'");
queryCount.setParameter(1, startDate);
queryCount.setParameter(2, endDate);
queryCount.setParameter(3, "'%"+userName+"%'");
queryCount.setParameter(4, startDate);
queryCount.setParameter(5, endDate);
queryCount.setParameter(6, "'%"+userName+"%'");
queryCount.setParameter(7, startDate);
queryCount.setParameter(8, endDate);
Object count =queryCount.uniqueResult();
//Query query = getSession().createSQLQuery(sql).addEntity(entityClass);
//query.list();
String sql1="select '请假',DEPTID,USERID,STARTDATE,ENDDATE,RECORDER,REMARK,ID from t_humn_leave where DELFLAG=0 and USERID in (select ID from T_APP_USER where NAME like ? ) and startDate between to_date(?, 'yyyy-mm-dd') and to_date(?, 'yyyy-mm-dd') " +
"union select '加班',DEPTID,USERID,startDate,endDate,RECORDER,REMARK,ID from t_humn_overtime where DELFLAG=0 and USERID in (select ID from T_APP_USER where NAME like ? ) and startDate between to_date(?, 'yyyy-mm-dd') and to_date(?, 'yyyy-mm-dd') " +
" union select '外出培训',DEPTID,USERID,startDate,endDate,RECORDER,REMARK,ID from t_humn_training where DELFLAG=0 and USERID in (select ID from T_APP_USER where NAME like ? ) and startDate between to_date(?, 'yyyy-mm-dd') and to_date(?, 'yyyy-mm-dd') ";
Query query=getSession().createSQLQuery(sql1);
query.setParameter(0, "%"+userName+"%");
query.setParameter(1, startDate);
query.setParameter(2, endDate);
query.setParameter(3, "%"+userName+"%");
query.setParameter(4, startDate);
query.setParameter(5, endDate);
query.setParameter(6, "%"+userName+"%");
query.setParameter(7, startDate);
query.setParameter(8, endDate);
System.out.println("三表总记录条数"+count);
chun518521 2012-04-06
  • 打赏
  • 举报
回复
quhuafeng521 2012-04-06
  • 打赏
  • 举报
回复
at com.pengtu.dao.human.LeaveDao.pageCount(LeaveDao.java:35)
在代码中。这是哪一行。

81,092

社区成员

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

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