0

I have a jsp which will hit the database and get the data of the table Employee_details which eill have five columns Id,Name,Department,salary,Manager. The below jsp displaying the whole table but i want to add pagination to it.Can some one help regarding this

 <%@page
        import="com.symp.DbUtil" import="java.sql.*"%>

 <html>
 <head>

    </head>


<body>

        <% 
Connection con;
DbUtil db;

db=new DbUtil();
con=db.getOracleConnection("oracle.jdbc.driver.OracleDriver",url,username,password);
System.out.println("connection is "+con);


Statement st=con.createStatement();

ResultSet resultset = 
    st.executeQuery("SELECT * FROM EMPLOYEE_DETAILS") ;

%>


  <TABLE id="results" >
        <TR>
            <TH>EMPLOYEE_ID</TH>
            <TH>Name</TH>
            <TH>SALARY</TH>
            <TH>DEPARTMENT</TH>
            <TH>MANAGER</TH>
        </TR>
        <% while(resultset.next()){ %>
        <TR>
            <TD> <%= resultset.getString(1) %></td>
            <TD> <%= resultset.getString(2) %></TD>
            <TD> <%= resultset.getString(3) %></TD>
            <TD> <%= resultset.getString(4) %></TD>
            <TD> <%= resultset.getString(5) %></TD>
        </TR>
        <% } %>   
    </TABLE>    

Rajasekhar
  • 787
  • 6
  • 13
  • 31

1 Answers1

0

You can use the DisplayTag JSP Tag library to easily achieve this:

http://www.displaytag.org/1.2/

However you will need to do some refactoring to either use the <sql:query /> tag or to put the resultset into a list of Beans (both of which are good things regardless as using Java code scriptlets in JSP pages went out of fashion at least 10 years ago):

http://www.tutorialspoint.com/jsp/jstl_sql_query_tag.htm

http://www.displaytag.org/1.2/tut_sources.html

And on the general point of using scriptlets:

How to avoid Java code in JSP files?

Community
  • 1
  • 1
Alan Hay
  • 22,665
  • 4
  • 56
  • 110