氟塑料離心泵www.buybeng.com

          jquery教程http://www.software8.co/wzjs/jquery/

          JSP讀取MySql數(shù)據(jù)庫實(shí)現(xiàn)分頁效果

          下面是用MV模式做的一個簡單的登錄后實(shí)現(xiàn)分頁顯示數(shù)據(jù)信息的頁面,后面會用MVC模式改寫。

          package com.ly.model;

          import java.sql.*;
          import java.util.ArrayList;

          public class UserbeanCl {
           private Statement st = null;
           private ResultSet rs = null;
           private Connection ct = null;
           private int pageSize = 10;
           private int rowCount = 0;
           private int pageCount = 0;

          //得到應(yīng)顯示的頁碼數(shù)

           public int pageCount() {
            try {
             // 得到連接
             ct = new connDB().getConn(); 
             st=ct.createStatement();
             rs = st.executeQuery("select count(*) from students");
             //
             if(rs.next()){
              
              rowCount=rs.getInt(1);
             }
             if(rowCount%pageSize==0){
              pageCount=rowCount/pageSize;
              
             }else{
              pageCount=rowCount/pageSize+1;    
             }
             
             
            } catch (Exception e) {
             e.printStackTrace();
            } finally {
             shutup();
            }
            return pageCount;

           }

          // 返回分頁信息,用ArrayList對象存儲

           public ArrayList getUsersByPage(int PageNow) {
            pageCount = pageCount(); 
            
            ct = new connDB().getConn(); 
            int startRow=(PageNow-1)*pageSize;
            ArrayList al = new ArrayList();
            
            try {
             st = ct.createStatement();
             rs=st.executeQuery("SELECT * FROM `students` LIMIT "+startRow+","+pageSize);
             while(rs.next()){
              
              Userbean ub=new Userbean();
              ub.setId(rs.getInt(1));
              ub.setName(rs.getString(2));
              ub.setGrade(rs.getInt(3));
              ub.setBatch(rs.getInt(4));
              ub.setPassword(rs.getInt(5));
              ub.setGxqm(rs.getString(6));
              al.add(ub);
              
             }

            } catch (Exception e) {
              e.printStackTrace();
            } finally {
             shutup();
            }

            return al;

           }

          //驗(yàn)證用戶登錄

           public boolean checkUser(String u, String p) {
            boolean b = false;
            ct = new connDB().getConn();
            try {
             st = ct.createStatement();
             ResultSet rs = st
               .executeQuery("select password from students where name='"
                 + u + "'");
             if (rs.next()) {
              // 說明用戶名存在
              if (rs.getString(1).equals(p)) {
               // 密碼正確
               b = true;
              } else {
               return false;
              }
             }

            } catch (Exception e) {
             e.printStackTrace();
            } finally {
             shutup();
            }
            return b;

           }

          // 關(guān)閉連接釋放資源

           public void shutup() {

            try {
             if (rs != null)
              rs.close();
            } catch (SQLException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
            } finally {
             try {
              if (st != null)
               st.close();
             } catch (SQLException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
             } finally {
              try {
               if (ct != null)
                ct.close();
              } catch (SQLException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
              }
             }
            }

           }

          }

          posted on 2012-10-13 08:55 你爸是李剛 閱讀(315) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          <2012年10月>
          30123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

          導(dǎo)航

          統(tǒng)計

          常用鏈接

          留言簿

          隨筆檔案

          文章檔案

          技術(shù)網(wǎng)站

          行業(yè)網(wǎng)站

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          站長網(wǎng) 氟塑料離心泵 注塑機(jī) 液晶廣告機(jī)
          主站蜘蛛池模板: 泰来县| 连州市| 稷山县| 清涧县| 靖安县| 秦安县| 册亨县| 烟台市| 北票市| 秭归县| 马关县| 菏泽市| 昭平县| 五指山市| 思茅市| 康乐县| 临夏市| 静宁县| 富源县| 合川市| 崇仁县| 白城市| 肥乡县| 富民县| 孟津县| 卓资县| 大关县| 岱山县| 南阳市| 侯马市| 宾阳县| 安丘市| 扶风县| 玉山县| 庄浪县| 门头沟区| 福建省| 英山县| 万山特区| 高清| 西藏|