• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Record is not getting pulled up from database

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to populate the textbox of my JSP page with the record which i'm trying to fetch.

Here is the JSP Code

<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();
%>
I'm able to retrieve the primary key(enrollmentno) from applicationContext, but using that primary key, record is not getting pulled up. I tried to print the value but all I'm getting is "null/0". So what should i do to fetch the record and populate the textfield of my JSP page.

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();
}
}
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What data type is enrollmentno? And can you share the StuAcadDetails class?

As an aside, note that it is not considered good practice to include Java code in a JSP. Especially database code. Among other issues, it makes the code hard to debug. Consider moving it to another class. (And reading about MVC for the future).
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first possibility is that enrollmentno is actually not the primary key of any record in that table.

The second possibility is that a record is actually returned, but your code ignores it. All I see in the posted code is assigning attributes of the record to variables, but I don't see any code using those variables.

There are other possibilities, including the possibility that an exception is thrown and then ignored.
 
Tushar Gosalia
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here Is The StuAcadDetails Class

@Table(name="ACADEMICS_DETAILS")
@Entity
public class StuAcadDetails {

@Id
@Column(name="ENROLLMENT_NUMBER")
private String enroll;

@Column(name="SEMESTER")
private int semester;

@Column(name="BRANCH")
private String branch;

@Temporal(TemporalType.DATE)
@Column(name="DATE_OF_JOINING")
private Date doj;

@Column(name="ATTDCE_IN_THEORY")
private int attThry;

@Column(name="ATTDCE_IN_PRACTICAL")
private int attPrac;

@Column(name="PREVIOUS_SEM_PERCENTAGE")
private float preSemPer;

@Column(name="OVERALL_AGGREGATE")
private float overallAggr;

@Column(name="SESSIONAL_PERCENTAGE")
private float sessPer;

@Column(name="PERFORMANCE")
private String performance;

/********************************Getters And Setters*************************************/
public String getEnroll() {
return enroll;
}
public void setEnroll(String enroll) {
this.enroll = enroll;
}
public int getSemester() {
return semester;
}
public void setSemester(int semester) {
this.semester = semester;
}
public String getBranch() {
return branch;
}
public void setBranch(String branch) {
this.branch = branch;
}
public Date getDoj() {
return doj;
}
public void setDoj(Date doj) {
this.doj = doj;
}
public int getAttThry() {
return attThry;
}
public void setAttThry(int attThry) {
this.attThry = attThry;
}
public int getAttPrac() {
return attPrac;
}
public void setAttPrac(int attPrac) {
this.attPrac = attPrac;
}
public float getPreSemPer() {
return preSemPer;
}
public void setPreSemPer(float preSemPer) {
this.preSemPer = preSemPer;
}
public float getOverallAggr() {
return overallAggr;
}
public void setOverallAggr(float overallAggr) {
this.overallAggr = overallAggr;
}
public float getSessPer() {
return sessPer;
}
public void setSessPer(float sessPer) {
this.sessPer = sessPer;
}
public String getPerformance() {
return performance;
}
public void setPerformance(String performance) {
this.performance = performance;
}

}
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So enrollmentno is a String. That increases the probability that it won't match any primary key from your table, because of minor differences like having extra (or missing) whitespace for example. I repeat my suggestion that you should compare the two.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic