zoukankan      html  css  js  c++  java
  • 数据分页查找心得总结

    1,request.getParamter()是返回String类型,而request.setAtrribute()是返回Object类型的,想要将Object类型 a  转换为String类型   String  b = a.toString(). 

    2,为了防止报空指针  所以接收的数据进行判断的时候都要放在equals()内。比如message!=null&&!"".equals(message).

    3,表单传输时一定要有method方法不然根本没有办法传输出去。

    4,使用方法传递数据到servlet中,servlet返回到界面时,一定要注意路径,路径必须是从目录出发的。

    5,统计数据库表中的数据条数 select count(*)as totalCount from demand_form    具体JavaBean代码如下:

         /**
      * 统计数据库中数据的总数
      */
     public int total() {
      int total = 0;
      Connection con = connect.getCon();
      PreparedStatement pstmt = null;
      ResultSet rs = null;
      try {
       pstmt = con.prepareStatement("select count(*)as totalCount from demand_form");
       rs = pstmt.executeQuery();
       if(rs.next()) {
        total = rs.getInt("totalCount");
       }
      } catch (SQLException e) {
       // TODO 自动生成的 catch 块
       connect.close(rs,pstmt, con);
      }
      return total;
     }

    按时间段查找数据 以及数据条数  select*from demand_form where date between '2019-03-05' and '2019-03-06' limit 0,5;

                                                         select count(*)as totalCount from demand_form where date between '2019-03-05' and '2019-03-06';

    具体Javabean代码

    /**
      * 按时间段查找需求表单
      */
     public ArrayList<demand> queryTimedemand(String date1,String date2,int a){
      Connection con = connect.getCon();
      ArrayList<demand> list = new ArrayList<>();
      PreparedStatement pstmt = null;
      ResultSet rs = null;
      try {
       pstmt = con.prepareStatement("SELECT*FROM demand_form where date BETWEEN '"+date1+"' and '"+date2+"' limit "+a*5+","+(a+1)*5);
          rs = pstmt.executeQuery();
       while (rs.next()) {
        demand dem = new demand();
        dem.Set(rs.getString(1), rs.getString(2), rs.getString(3).split("&"), rs.getString(4), rs.getDouble(5), rs.getString(6),rs.getString(7),rs.getString(8));
        dem.setPass(rs.getString(9));
        list.add(dem);
       }
       return list;
      } catch (SQLException e) {
       // TODO 自动生成的 catch 块
       e.printStackTrace();
       return null;
      } finally {
       connect.close(rs,pstmt, con);
      }
      
     }
     
     /**
      * 按时间段统计表单数据条
      */
     public int Timetotal(String date1,String date2) {
      int total = 0;
      Connection con = connect.getCon();
      PreparedStatement pstmt = null;
      ResultSet rs = null;
      try {
       pstmt = con.prepareStatement("select count(*)as totalCount from demand_form where date BETWEEN '"+date1+"' and '"+date2+"'");
       rs = pstmt.executeQuery();
       if(rs.next()) {
        total = rs.getInt("totalCount");
       }
      } catch (SQLException e) {
       // TODO 自动生成的 catch 块
       connect.close(rs,pstmt, con);
      }
      return total;
     }

  • 相关阅读:
    CI框架源码解析十九之分页类文件Pagination.php
    sublime新代码段
    sublime
    递归调用详解,分析递归调用的详细过程
    什么是锚点?锚点应该如何用?
    PHP中spl_autoload_register函数的用法
    PHP 构造方法 __construct()
    工欲善其事,必先利其器---IDE使用
    Apache操作
    js中常用的操作
  • 原文地址:https://www.cnblogs.com/goubb/p/10481044.html
Copyright © 2011-2022 走看看