氟塑料離心泵www.buybeng.com

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

          JSP讀取MySql數據庫實現分頁效果

          下面是用MV模式做的一個簡單的登錄后實現分頁顯示數據信息的頁面,后面會用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;

          //得到應顯示的頁碼數

           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;

           }

          //驗證用戶登錄

           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;

           }

          // 關閉連接釋放資源

           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)  編輯  收藏


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


          網站導航:
           
          <2012年10月>
          30123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          文章檔案

          技術網站

          行業網站

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          站長網 氟塑料離心泵 注塑機 液晶廣告機
          主站蜘蛛池模板: 双柏县| 万山特区| 武功县| 旅游| 正阳县| 札达县| 利辛县| 合江县| 通河县| 禹城市| 西华县| 无棣县| 奉化市| 叙永县| 佛山市| 封开县| 瑞安市| 宁晋县| 乌什县| 易门县| 锦屏县| 平塘县| 密山市| 静宁县| 龙海市| 共和县| 宁阳县| 丰原市| 阳谷县| 改则县| 榆社县| 安陆市| 定兴县| 新乡市| 四川省| 轮台县| 建昌县| 乐安县| 溆浦县| 通城县| 苍梧县|