Previous | Home | Next |
For making these application we are using the NetBeans and appache tomcat server and mysql server. As we discussed in last application There we have discussed how to send data into the database using hibernate with the action of servlet. Now we will work how can we show the data on the jsp page in a table formate for showing the report chart. For this time of Application we need to Follow some basic step which we have given here:
Step 1. We will work on the same application(HibernateApplicationUsingServlet) name as we given in the insert operation example and here database will be same and table name also will be same.
In the above image we can see the what we need to do in this session. By which action and where we need to peroform the action.
Step 2. Now we need to create a jsp page(FetchDataList) for making the action to show the database table on the jsp page in a table formate. For this we need to go in the File menu wizared as we given in the last example for taking the jsp file. Than we need to go in the New file option of File Menu Wizard then search to web and click on jsp page which is shown in the next tab of the web and after the clicking on the next a window will be open put name of that file and click finish.
index.jsp
<%@page import="org.hibernate.criterion.Restrictions" %> <%@page import="org.hibernate.*" %> <body bgcolor="lightyellow"> <table width="500" border="1"><tr><th>Sr. No</th><th>First Name</th><th>Last Name</th><th>Age</th> <th>When Inserted</th></tr> <% SessionFactory sf = r4r.HibernateUtil.getSessionFactory(); Session s = sf.openSession(); Transaction tr = s.beginTransaction(); Criteria cr = s.createCriteria(r4r.InsertData.class); java.util.List<r4r.InsertData> us = cr.list(); for(r4r.InsertData dr : us) { out.println("<tr><td>"+dr.getId()+ "</td><td>"+dr.getFirstName()+"</td><td>" +dr.getLastName()+"</td><td>"+dr.getAge()+ "</td><td>"+dr.getLastUpdate()+"</td><tr>"); } out.println("<h2>We have found these some data which is given in the table from the database"); %> </table> </body>
Step 4. Now build the project and run the project.
Here the above example we can show the database data into the jsp page as a table formate. If any where we required any kind of report.
Previous | Home | Next |