Display ResultSet Using < h:dataTable >

Normally we are using list ,set or any other collection framework in <h:dataTable> ..but if you wish you can also use the content of result set into your data table .
<h:dataTable> is mainly used for displaying data on your jsp page in a proper way.
Here i made a simple JSF application in which there is one search page .
On clicking on "Search" button it will display data from database in same page (same jsp)

//Search.jsp



 

Specify your search criteria

Name City Experience(In Month) Experience(Technology)  

Output of above jsp code

So in above search.jsp on click on "Search" button it will call method of ManageBean named as "SearchBean.java".





//SearchBean.java

 public class SearchBean {


 private String name;
 private String city;
 private String experience;
 private String techExperience;
 private ResultSet rs;




 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public String getCity() {
  return city;
 }
 public void setCity(String city) {
  this.city = city;
 }
 public String getExperience() {
  return experience;
 }
 public void setExperience(String experience) {
  this.experience = experience;
 }
 public String getTechExperience() {
  return techExperience;
 }
 public void setTechExperience(String techExperience) {
  this.techExperience = techExperience;
 } 

 public ResultSet getRs() {
  return rs;
 }
 public void setRs(ResultSet rs) {
  this.rs = rs;
 }




public String doSearch() throws SQLException
 {

 //create database connection

 //create statement object  here for example take it as a stmt.


 Resultset resultSet = null;
 resultSet = stmt.executeQuery("Select * From tablename");

 setRs(resultSet);
 }


}



On click on Search button doSearch action is called in which it will fire the query and set the result set into bean.
So if you want to display this result set data into Search.jsp ..without using list or set then use below code


//Display data on same jsp by using data of resultset



        
        
         
             



        
        
         
             



        
        
         
             



        
        
         
             



        
        
         
             



        
        
         
             







Next PostNewer Post Previous PostOlder Post Home