用myclise+tomcat5.0.28怎么经常出现问题,自动生成的还是出现问题。在线等,帮忙解决。
解决方案 »
- 跳转页面出错,求指教
- java quartz,写了具体的JOB后,怎么设置才能让quartz随 JBOSS 或 TOMCAT 工作起来
- struts上传文件出现Servlet execution threw an exception
- 未成年的程序员想来广州找工作
- 关于quartz任务在应用服务器上遇到的问题求救
- 数据库查询问题
- [100分] 在hibernate中identity和increment有什么区别,到底identity怎样使用,解释的清楚给个例子马上揭贴!
- jsf的问题
- 请问 JVM 是什么 ,它与JDK有什么区别?
- 用JAVA进行DOM开发问题
- Hibernate3的查询问题
- 谁有能力开发搜索工具条的进来看看。。。
Query query=session.createQuery("select u from usertable as u where username='" +
userName + "'");
try{
Iterator it = query.iterate();
ul = (Usertable) it.next();
从你的代码有两点是存在问题的:
1.("select u from usertable as u where username='" +userName + "'");这种hql的构造方法是项目实际开发应该避免的,应该使用匹配符的方式来构造(用?),这样做会导致中文内容的传入而出现乱码。
应该这样:
("select u from usertable as u where username=?",参数);
2.Iterator it = query.iterate();ul = (Usertable) it.next();
你这样写肯定是有问题的,如果没有数据内容检索出来,那当然要报异常啊!
应该是:Iterator it = query.iterate();
if(it.hasNext())
ul = (Usertable) it.next();
综上所述:你的问题我估计是中文名的传入导致无法取得数据库数据,所以后面的Iterator读取就失败了,自己好好检查一下,祝你好运!
select u from usertable as u where username='" +userName + "'
应该没有"as"才对
select u from usertable u where username='" +userName + "'