zoukankan      html  css  js  c++  java
  • sql分页查询

    /**
         * 按分页查询
         */
        public List<Article> getPageList( int page) {
            PreparedStatement pstm = null;
            ResultSet rs = null;
            String strSql = null;
            List<Article> list=new ArrayList<>();   //实例化范型对象,保存查询的的结果集对象
            try {
                strSql = "select*from article LIMIT ?,?;";   //查询语句,第一个参数查询数据的初始位置,第二个参数查询的数据条数。
                pstm =  conn.prepareStatement(strSql);
                // 如果使用静态的SQL,则不需要动态设置参数
                pstm.setInt(1, (page-1)*Article.getPageSize());查询语句,第一个参数查询数据的初始位置
                pstm.setInt(2, Article.getPageSize());第二个参数查询的数据条数。
                // 执行赋值后SQL,
                rs=pstm.executeQuery();
                //判断是否有返回结果,有下一行rs.next()方法为true
                while(rs.next()) {  取结果集的里的数据,article
                    Article article=new Article();
                    article.setArid(rs.getInt("arid"));
                    article.setArtitle(rs.getString("artitle"));
                    article.setArcontent(rs.getString("arcontent"));
                    list.add(article); //把article对象添加到范型对象保存
                }
                System.out.println("插入数据成功。。。。。。。。" + strSql);

            } catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();
            }
            return list;   //返回值,list对象
     }

  • 相关阅读:
    vcsa7.0可能不兼容esxi6.7
    使用livecd 更改root密码
    虚拟机初始化脚本
    一句话修改UUID
    vcsa 6.7 u1升级6.7 u2--6.7U3---6.7U3c
    【转载】:FreeRadius安装及与openldap的连接(centos 7 环境)
    freeradius 关联LDAP认证-按属性过滤LDAP目录中的用户
    使用包ldap3进行Python的LDAP操作
    2020年1月29日-学习flask第一天
    Python-xlwt库的基本使用
  • 原文地址:https://www.cnblogs.com/TangGe520/p/8873252.html
Copyright © 2011-2022 走看看