注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Search的博客

不断学习中!

 
 
 

日志

 
 

jsp数据分页技术  

2012-12-27 11:23:11|  分类: 默认分类 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

<%@ page language="java" import="java.sql.*" pageEncoding="gb2312"%> 

  <body bgcolor=white>

    <center>

       <table width="600" border="2" cellspacing="1" cellpadding="1">

      <tr align="center">

       <td height="30" align="center" ><span class="goodtitle"><font size=6 face="幼圆">查询商品列表</font></span></td>

        </tr>

        </table>

           <table width="600" border="2" cellspacing="0" cellpadding="0" height="10">

            <tr>

           <td width="120" height="10" align="center">商品名称</td>

           <td width="120" height="30" align="center">商品类型</td>

           <td width="120" height="30" align="center">商品价格</td>

           <td width="120" height="30" align="center">库存数量</td>

           <td width="120" height="30" align="center">制造商</td>

           </tr>

           <%

              String key1=(String)session.getAttribute("key1");

              String key=(String)session.getAttribute("key");

                    int PageSize=5;

                    int RecordCount;

                    int PageCount;

                    int Page=1;

                    int i;

                    String SPage=request.getParameter("page");

                    if(SPage==null){

                       Page=1;

                       }

                       else{

                       Page=java.lang.Integer.parseInt(SPage);

                       if(Page<1)Page=1;

                    }

                    String sql="SELECT * FROM Goods WHERE "+key1+" LIKE '%"+key+"%'";

                   

                     

                       Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

                             Connection con=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=SelectGoods","sa","000");

                             Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);

                             ResultSet rs=stmt.executeQuery(sql);

                             rs.last();

                             RecordCount=rs.getRow();

                           

                      

                             

                             PageCount=(int)(RecordCount+PageSize-1)/PageSize;

                             if(Page>PageCount)

                             Page=PageCount;

                             if(PageCount>0){

                                rs.absolute((Page-1)*PageSize+1);

                                i=0;

                                while(i<PageSize&&!rs.isAfterLast()){

                     %>

                     <tr>

                        <td width="120" height="10" align="center"><%=rs.getString("name") %></td>

                        <td width="120" height="10" align="center"><%=rs.getString("model") %></td>

                        <td width="120" height="10" align="center"><%=rs.getFloat("price") %></td>

                        <td width="120" height="10" align="center"><%=rs.getInt("number") %></td>

                        <td width="120" height="10" align="center"><%=rs.getString("maker") %></td>

                     </tr>

                     <%

                       rs.next();

                       i++;

                       }

                       }

                       %>

                       </table>

                       <hr>

                       <h5>

                       <div align="center">

                         <%=Page %>     <%=PageCount %>

                         <%

                           if(Page<PageCount){

                         %>

                         <a href="PageShow.jsp?page=<%=Page+1%>">下一页</a>

                         <%

                           }

                           if(Page>1){ %>

                           <a href="PageShow.jsp?page=<%=Page-1 %>">上一页</a>

                           <%

                            }

                            %>

                          

                            </div>

                            </h5>

                    </center>

  </body>

</html>

  评论这张
 
阅读(155)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017