⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 userinfopage.java~3~

📁 一个基于JAVA的BS结构的宠物诊所管理系统.是当年在学校时写的,大家指点一下.
💻 JAVA~3~
字号:
package gxaccp.t07.guoneng_wei.petclinicmanagesystem.beans;

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

import gxaccp.t07.guoneng_wei.jdbc.*;

public class UserInfoPage {
  private int currentPage = 1; //当前是第几页
  private int maxPage = 0; //一共有多少页
  private int maxRowCount = 0; //一共有多少行
  private int rowsPerPage = 5; //每页多少行
  private Vector data = new Vector();

//关于动态的字符串,是不可以在对象最初生成的时候就初始化的,而应该用方法动态操作
  private String queryString ="";

  public UserInfoPage() {

  }

  public void init(Connection con) {
    this.setMaxRowCount(this.rowsCount(con));
    this.setMaxRowCount(this.rowsCount(con));
    this.setMaxPage(this.evaluMaxPage());
    this.setData(this.selectData(con));
    System.out.println(this.queryString);
  }

  public void setCurrentPage(int currentPage) {
    this.currentPage = currentPage;
  }

  public void setMaxPage(int maxPage) {
    this.maxPage = maxPage;
  }

  public void setMaxRowCount(int maxRowCount) {
    this.maxRowCount = maxRowCount;
  }

  public void setRowsPerPage(int rowsPerPage) {
    this.rowsPerPage = rowsPerPage;
  }

  public void setData(Vector data) {
    this.data = data;
  }

  private void setQueryString() {
//关于动态的字符串,是不可以在对象最初生成的时候就初始化的,而应该用方法动态操作
    this.queryString = "SELECT TOP " + this.rowsPerPage +/*每页多少行*/
      " * FROM topic WHERE TopicID NOT IN(SELECT TOP " +
      ( (this.currentPage - 1) * this.rowsPerPage) +
      " TopicID FROM topic )"; /*当前页码-1乘以每页最大行数*/
  }

  public int getCurrentPage() {
    return currentPage;
  }

  public int getMaxPage() {
    return maxPage;
  }

  public int getMaxRowCount() {
    return maxRowCount;
  }

  public int getRowsPerPage() {
    return rowsPerPage;
  }

  public Vector getData() {
    return data;
  }

  public String getQueryString() {
    this.setQueryString();
    return queryString;
  }

  private Vector selectData(Connection con) {
    Vector v = new Vector();
    try {
      ResultSet rs = DataBaseAccess.select(con, this.getQueryString());//注意
      while (rs.next()) {
//        TopicBean tb = new TopicBean();
//        tb.setAuthor(rs.getString("Author"));
//        tb.setContent(rs.getString("Content"));
//        tb.setTitle(rs.getString("Title"));
//        v.addElement(tb);
      }
      DataBaseAccess.closeResultSet(rs);
    }
    catch (Exception ex) {
    }
    return v;
  }

  private int rowsCount(Connection con) {
    String select = "SELECT COUNT(*) FROM topic";
    int rowsNum = 0;
    try {
      ResultSet rs = DataBaseAccess.select(con, select);
      if (rs.next()) {
        rowsNum = rs.getInt(1);
      }
      DataBaseAccess.closeResultSet(rs);
    }
    catch (Exception ex) {
    }
    return rowsNum;
  }

  private int evaluMaxPage() {

    if (this.maxRowCount % this.rowsPerPage == 0) {
      return this.maxRowCount / this.rowsPerPage;
    }
    else {
      return this.maxRowCount / this.rowsPerPage + 1;
    }
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -