mercredi 15 juillet 2015

i am not getting values from jdbc table in jsf

I tried a lot but i am not getting values from my database(Yes it has datas in it and i have been using in other views!). i dont even get any error messages.Can anyone tell me whats error please?

controller.java

@ManagedBean (name="StudentController")
@SessionScoped
public class StudentController {


    private Student student = new Student();

    public Student getStudent() {
        return student;
    }

    public void setStudent(Student student) {
        this.student = student;
    }

    public List<Student>getstudentList(){

        List<Student> studentlist = new ArrayList<Student>();
         PreparedStatement ps = null;
         ResultSet rs = null;
        Connection con = null;

        try{
           Class.forName("org.apache.derby.jdbc.ClientDriver");
           con = DriverManager.getConnection("jdbc:derby://localhost:1527/XXX","XXX","XXX");
           String sql = "Select * from student";
           ps = con.prepareStatement(sql);
           rs = ps.executeQuery();

           while(rs.next()){
           Student student = new Student();
           student.setFname(rs.getString("FNAME"));
           student.setLname(rs.getString("LNAME"));
           student.setStudentId(rs.getString("STUDENTID"));
studentlist.add(student);
         // return list;
           }

        }catch(Exception e){
            e.printStackTrace();
        }


        return studentlist;
}
}

student.java

public class Student {
 @Id  private String StudentId;
   private String Fname, Lname, Mname="noname";
/********getters and setters******/

}

records.xhtml

<h:dataTable  value="#{StudentController.getstudentList()}" var="student" styleClass="studentTable"
                         columnClasses=",,,fixedWidth">
                <h:column>
                    <f:facet name="header">Student ID</f:facet>
                    <h:outputText value="#{student.studentId}"></h:outputText>
                </h:column>

            <h:column>
                <f:facet name="header">Name</f:facet>
                <h:outputText value="#{student.fname}"></h:outputText>
            </h:column>

                <h:column>
                    <f:facet name="header">Surname</f:facet>
                    <h:outputText value="#{student.lname}"></h:outputText>
                </h:column>

                <h:column>

                    <f:facet name="header">Action</f:facet>
                     <h:form>
                         <h:commandLink value="Update">

                    </h:commandLink>
                    </h:form>
                </h:column>

           </h:dataTable> 

Aucun commentaire:

Enregistrer un commentaire