静止的流水 发表于 2009-12-10 10:34

mysql数据查询分页


%!String start;%>
%!int prepage;%>
%!int nextpage;%>
%
start =request.getParameter("st");
int st = Integer.parseInt(start);
prepage = st - 10;
nextpage = st+10;
                  String driver = "com.mysql.jdbc.Driver";
         String url = "jdbc:mysql://localhost:3306/medicine";
         String user = "root";
         String password = "hello";
         try {
            Class.forName(driver);
            Connection conn = DriverManager.getConnection(url, user, password);
            Statement statement = conn.createStatement();
            String sql = "select * from bbs order by time desc limit "+st+",10";
               ResultSet rs = statement.executeQuery(sql);
                out.println("100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
                out.println("");
            String name = null;
            while(rs.next())
            {
               
                out.println("+rs.getString("href")+" target=\"_blank\">"+rs.getString("title")+"");
                            out.println("overhide80\">"+rs.getString("source")+"");
                            out.println(""+rs.getString("time")+"");
            }
            rs.close();
            conn.close();
         }catch(ClassNotFoundException e) {
         out.println("error,class not found");
            e.printStackTrace();
         } catch(SQLException e){
            e.printStackTrace();
         } catch(Exception e) {
            e.printStackTrace();
         }
         out.println("");
%>
div class="p">
a href=morebbsnews.jsp?st=%=prepage%>&nd=10>上一页/a>
a href=morebbsnews.jsp?st=0&nd=10>/a> 
a href=morebbsnews.jsp?st=10&nd=10>/a> 
a href=morebbsnews.jsp?st=20&nd=10>/a> 
a href=morebbsnews.jsp?st=30&nd=10>/a> 
a href=morebbsnews.jsp?st=40&nd=10>/a> 
a href=morebbsnews.jsp?st=50&nd=10>/a> 
a href=morebbsnews.jsp?st=60&nd=10>/a> 
a href=morebbsnews.jsp?st=70&nd=10>/a> 
a href=morebbsnews.jsp?st=80&nd=10>/a> 
a href=morebbsnews.jsp?st=90&nd=10>/a> 
a href=morebbsnews.jsp?st=%=nextpage%>&nd=10>下一页/a>
/div>br>;
/body>
/html>
小小的一个小程序,见笑了


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/80678/showart_2116150.html
页: [1]
查看完整版本: mysql数据查询分页