用hibernateTemplate时执行query.list()时报错,query对象看后台输出已经获取到了,但执行query.list()方法就报错,求大神
java代码:
String sql="select count(*) from Employee where name="+name+" and password="+password;
Query query=hibernateTemplate.getSessionFactory().getCurrentSession().createSQLQuery(sql);
System.out.println("Query:"+query.toString());
List result=query.list();
在jsp界面输入值:name,111; password,1
后台输出:
Query:SQLQueryImpl(select count(*) from Employee where name=111 and password=1)
Hibernate: select count(*) from Employee where name=111 and password=1
7316 [http-8080-1] WARN org.hibernate.util.
JDBCExceptionReporter - SQL Error: 1722, SQLState: 42000
7316 [http-8080-1] ERROR org.hibernate.util.JDBCExceptionReporter - ORA-01722: 无效数字
报错:
Struts Problem Report
Struts has detected an unhandled exception:
Messages: ORA-01722: ????
could not execute query
File: oracle/jdbc/driver/DatabaseError.java
Line number: 112
--------------------------------------------
Stacktraces
org.hibernate.exception.SQLGrammarException: could not execute query
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
org.hibernate.loader.Loader.doList(Loader.java:2536)
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
org.hibernate.loader.Loader.list(Loader.java:2271)
org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:316)
org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1842)
org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165)
org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:157)
com.skyarm.service.EmployeeLogService.loginTest2(EmployeeLogService.java:55)
com.skyarm.service.EmployeeLogService$$FastClassByCGLIB$$37b03b1e.invoke()
net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:688)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621)
com.skyarm.service.EmployeeLogService$$EnhancerByCGLIB$$b4ff9a3f.loginTest2()
com.skyarm.action.EmployeeAction.login(EmployeeAction.java:34)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
&