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

📄 usebean.java

📁 一般性的内容,可以生成和修改还在有其他的好友添加等等
💻 JAVA
字号:
package zd.bbs;
import java.sql.*;
import java.util.*;

public class UseBean {
 private int curtpage=1;  //当前页
 private int allpage;  //一供多少页
 public int rowspage=10; //一页多少记录
 private int allrows;  //共多少记录
 public Vector data;
 public  int lid;
 public  UseBean () throws Exception 
 {
  this.setBean();  //在这初始化一下是为了在JSP页面中一开始就能得到数据库中的记录

 }
 public int getCurtpage()
 {
  return curtpage;
 }
 public void setCurtpage(int curtpage)
 {
  this.curtpage=curtpage;
 }
 public int getAllpage()
 {
  return allpage;
 }
 public void setAllpage(int allpage)
 {
  this.allpage=allpage;
 }
 public int getAllrows()
 {
  return allrows;
 }
 public void setAllrows(int allrows)
 {
  this.allrows=allrows;
 }
 
 public int getallpages() throws Exception
 {
  //求出一共多少页
  String sql = "select * from talk where model_id2=1";
  DataBaseConnection con = new DataBaseConnection();
  Connection conn= con.getConnection();
     Statement stmt = conn.createStatement();
     ResultSet st = stmt.executeQuery(sql);
     int i=0;
     while(st.next())
     {
      i++;
     }
     return i;
 }
 public UseBean getResultpage(String page) throws Exception  //得到要显示的那一页的记录
 {
  UseBean ub= new UseBean();
  int pagenum = Integer.parseInt(page);
  //String sql="select top "+rowspage+" * from talk where  model_id2=1 and talk_id not in (select top "+(pagenum-1)* ub.rowspage+" talk_id from talk where model_id2=1 order by talk_id desc )order by talk_id desc";  //得到是要显示在本页的及以前的数据记录之各
  String sql="select top "+pagenum*ub.rowspage+" * from talk where model_id2=1 order by talk_id desc";
  Vector v = new Vector();     // 定义一个数据集
  DataBaseConnection con = new DataBaseConnection();
  Connection conn= con.getConnection();
  Statement stmt = conn.createStatement();
  ResultSet rs = stmt.executeQuery(sql);
  int i=0;
  while(rs.next())
  {
   if(i>(pagenum-1)*ub.rowspage-1)      //控制只把本页的数据赋到object对象中
   {
   Object[] object = new Object [3]; 
   object [0] = rs.getString(1);
   object [1] = rs.getString(2);
   object [2] = rs.getString(3);
   v.add(object);
   }
   i++;
  }
  rs.close();
  stmt.close();
  ub.setCurtpage(pagenum);     //设置当前为第几页
  ub.data=v;                          //把数据集V赋给数据集data
  return ub;
 }

 public void setBean() throws Exception  //设置总行数和设置总业数
 {
  this.setAllrows(this.getallpages());    //设置总行数
  if(this.allrows%this.rowspage==0)
  {
   this.allpage = this.allrows/this.rowspage;  //设置总页数:正好是整数倍的
  }
  else
  {
   this.allpage=this.allrows/this.rowspage+1;  //设置总页数: 不是整数倍的
  }
  
 }
public int id(int lid){
	this.lid=lid;
	return lid;
	
}

}

⌨️ 快捷键说明

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