无法从数据库中获取记录

时间:2014-02-25 14:51:26

标签: mysql sql hibernate jsp

我想用我正在尝试获取的记录填充JSP页面的文本框。

这是JSP代码

<BODY> 
<jsp:useBean id="Stu_Info" class="org.student.entity.RegistrationStudent" scope="application"> 
<% 
enrollmentno=Stu_Info.getEnroll(); 

HibernateUtils utility=new HibernateUtils(); 
Session sessionn=utility.getSession(); 
Transaction tx=sessionn.beginTransaction(); 

List<StuAcadDetails> detail=sessionn.createCriteria(StuAcadDetails.class).add(Restrictions.idEq(enrollmentno)).list(); 


for(StuAcadDetails stuDetails:detail) 
{ 
attPrac=stuDetails.getAttPrac(); 
attThry=stuDetails.getAttThry(); 
branch=stuDetails.getBranch(); 
doj=stuDetails.getDoj(); 
overallAgg=stuDetails.getOverallAggr(); 
performance=stuDetails.getPerformance(); 
preSemPer=stuDetails.getPreSemPer(); 
semester=stuDetails.getSemester(); 
sessPer=stuDetails.getSessPer(); 
} 
tx.commit(); 
sessionn.close(); 
%>

我可以从applicationContext中检索主键(enrollmentno),但是使用该主键,记录不会被提升。我试图打印该值,但我得到的只是“null / 0”。那么我该怎么做才能获取记录并填充我的JSP页面的文本字段。

HibernateUtils

public class HibernateUtils { 

static SessionFactory sessionfactory; 

static 
{ 
Configuration cfg=new Configuration().configure("/org/student/hibernate.cfg.xml"); 
ServiceRegistry registry=new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry(); 
sessionfactory=cfg.buildSessionFactory(registry); 
} 

public static SessionFactory getSessionFactory() 
{ 
return sessionfactory; 
} 

public static Session getSession() 
{ 
return sessionfactory.openSession(); 
} 
}

0 个答案:

没有答案