我的评论

re: Struts+Spring+Hibernate练习(完整) mingyue 2006-09-22 20:09  
首先谢谢楼主,让我们这些初学者受益非浅!我认真看过本集的录像,也按楼主的操作无误,可是在UserDAOImp类中的方法处总是出错:
package com.test;
import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.test.hibernate.User;
public class UserDAOImp extends HibernateDaoSupport implements UserDAO {

private static String hql = "from User u where u.username=? and password=?";
public boolean isValidUser(String username, String password) {

String[] userlist=new String[2];
userlist[0]=username;
userlist[1]=password;
List userList = this.getHibernateTemplate().find(hql,userlist);

if (userList.size() > 0) {
return true;
}
return false;
}
}
最后运行导致以下错误:
javax.servlet.ServletException: Hibernate operation: could not execute query; uncategorized SQLException for SQL [select user0_.ID as ID, user0_.USERNAME as USERNAME0_, user0_.PASSWORD as PASSWORD0_ from user user0_ where USERNAME=?]; SQL state [HY000]; error code [1266]; Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='; nested exception is java.sql.SQLException: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:523)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: could not execute query; uncategorized SQLException for SQL [select user0_.ID as ID, user0_.USERNAME as USERNAME0_, user0_.PASSWORD as PASSWORD0_ from user user0_ where USERNAME=?]; SQL state [HY000]; error code [1266]; Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='; nested exception is java.sql.SQLException: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='
org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.translate(SQLStateSQLExceptionTranslator.java:96)
org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.translate(SQLErrorCodeSQLExceptionTranslator.java:257)
org.springframework.orm.hibernate3.HibernateAccessor.convertJdbcAccessException(HibernateAccessor.java:424)
org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:411)
org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:363)
org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:800)
org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:796)
com.test.UserDAOImp.isValidUser(UserDAOImp.java:27)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:324)
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:292)
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:155)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:122)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
$Proxy1.isValidUser(Unknown Source)
com.test.struts.action.LoginAction.execute(LoginAction.java:58)
org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:106)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

请楼主或各位同仁帮忙解决哦!此问题让我郁闷了一整天了哦!
我屏蔽这个isValidUser函数之后,就没有这个问题了哦!而且我在此基础上配置了续集,均成功!!!新增、删除、浏览都正确哦!

先谢了哦!

<2024年11月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

导航

统计

常用链接

留言簿(2)

随笔档案

nice blog

搜索

最新评论

阅读排行榜

评论排行榜