Jsp+oracle implementing database content in a tabular format in the foreground (including pagination)
New list_emp.jsp in Folder
The code is as follows:
1<%@ page contenttype= "text/html" pageencoding= "GBK"%>2<%@ pageImport= "Java.sql.*"%>345<body>6<%!7 //Defining Database Drivers8 PublicString dbdriver= "Oracle.jdbc.driver.OracleDriver"; 9 //Database Connection AddressTen PublicString dburl= "Jdbc:oracle:thin: @localhost: 1521:yy"; One PublicString dbuser= "Scott"; A PublicString dbpass= "Tiger"; - -%> the<% -Connection conn=NULL; -PreparedStatement pstmt=NULL; -ResultSet rs=NULL; +%> -<% + Try{ A Class.forName (Dbdriver); atconn=drivermanager.getconnection (Dburl,dbuser,dbpass); - intPagesize=3; - intPagenow=1;//show first page by default - introwcount=0;//total number of pens - intPagecount=0; -String s_pagenow= (String) request.getparameter ("Pagenow"); in if(s_pagenow!=NULL){ -Pagenow =Integer.parseint (S_pagenow); to } +String SQL1 = "SELECT count (*) from EMP"; -pstmt=conn.preparestatement (SQL1); thers=Pstmt.executequery (); * if(Rs.next ()) { $RowCount = Rs.getint (1); Panax Notoginseng } - if(rowcount%pagesize==0){ thePageCount = rowcount/pageSize; +}Else{ APageCount = rowcount/pagesize + 1; the } +String sql= "Select Empno,ename,job,hiredate,sal from (select A1.*,rownum rn from (SELECT * from emp ORDER BY sal Desc) A1 where rownum<= "+pagesize*pagenow+") where rn>= "+ ((pageNow-1) *pagesize+1); -pstmt=conn.preparestatement (SQL); $rs=Pstmt.executequery (); $%> -<center> -<table border= "1" width= "80%" > the<tr> -<td> Employee Number </td>Wuyi<td> Employee Name </td> the<td> Employee Work </td> -<td> Employee Dates </td> Wu<td> Employee Wages </td> -</tr> About<% $ while(Rs.next ()) { - intEmpno=rs.getint (1); -String ename=rs.getstring (2); -String job=rs.getstring (3); AJava.util.Date Date=rs.getdate (4); + floatSal=rs.getfloat (5); the%> -<tr> $<td><%=empno%></td> the<td><%=ename%></td> the<td><%=job%></td> the<td><%=date%></td> the<td><%=sal%></td> -</tr> in<% the } the%> About</table> the<form action= "" method= "POST" > the<% the for(inti=1;i<=pagecount;i++){ +Out.println ("<a href=list_emp.jsp?pagenow=" +i+ ">[" +i+ "]</a>"); - } the if(Pagenow! = 1){ BayiOut.println ("<a href=list_emp.jsp?pagenow=1> home </a>"); theOut.println ("<a href=list_emp.jsp?pagenow=" + (pageNow-1) + "> Previous </a>"); the } - if(Pagenow! =PageCount) { -Out.println ("<a href= list_emp.jsp?pagenow=" + (Pagenow + 1) + "> Next </a>"); theOut.println ("<a href= list_emp.jsp?pagenow=" + pagecount+ "> last page </a>"); the } the%> the</form> -</center> the<% the}Catch(Exception e) { the System.out.println (e); 94 } the finally{ the Try{ the Rs.close (); 98 Pstmt.close (); About Conn.close (); -}Catch(Exception e) {101 System.out.println (e); 102 } 103 } 104%> the</body>106From: http://blog.csdn.net/josephiney/article/details/6989841
Jsp+oracle implementing database content in a tabular format in the foreground (including pagination)