栏目导航
热点推荐
- 测试你对技术的掌握度:JSP程序
- Eclipse 3.0 上配置JSP开发环境
- Jsp基础知识总结
- 整合Tomcat4.1和IIS5 直到能够正
- JSP服务器的安装与配置(带数据库
- 在JSP环境中如何配置和使用fcked
- JSP中表单数据存储的通用方法
- 在JSP环境中如何来配置和使用fck
- Oracle数据库和JSP连接要注意的
阅览排行
JSP初级教程--JSP初学者入门之五
www.jz123.cn 2010-03-12 来源: 中国建站 责任编辑(袁袁) 我要投递新闻
//根据maxRowCount和onePageRowCount计算出maxPageCount并返回
public int getMaxPageCount()
{
if (maxRowCount%onePageRowCount==0)
maxPageCount=maxRowCount/onePageRowCount;
else
maxPageCount=maxRowCount/onePageRowCount+1;
return maxPageCount;
}
}
---------------------------------------------------------------------------------
----------------------------CountBean.java------------------------------------
//该bean用于接收具体页数然后返回该页应显示的记录
package ringz.javabeans;
import java.util.*;
import java.io.*;
import java.sql.*;
public class CountBean
{
private int pageNum;//当前是第几页
private String classforname;
private String servanddb;
private String sql;
Vector v=new Vector();
//得到关于目标数据库的搜索条件
public void setSql(String s1,String s2,String sqlstr)
{
this.classforname=s1;
this.servanddb=s2;
this.sql=sqlstr;
}
//得到pageNum
public void setPageNum(int pagenum)
{
this.pageNum=pagenum;
}
//返回结果
public Vector getResult(String listname[])throws Exception
{
int num=listname.length;//得到数组的长度
String listName[]=new String[num];//定义一个大小为num的string型数组
for(int i=0;i<num;i++)
listName[i]=listname[i];//将目标数组的内容传给listName数组
try
{
Class.forName(classforname);
Connection con=DriverManager.getConnection(servanddb);
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(sql);
int i=1;
while(rs.next())
{
Object[] obj=new Object[num];
for(int j=0;j<num;j++)
obj[j]=rs.getString(listName[j]);
v.add(obj);
i++;
}//while
rs.close();
stmt.close();
con.close();
return v;
}//try
catch(Exception e)
{
e.printStackTrace();
throw e;
}//catch
}
}
上一篇:JSP初级教程--JSP初学者入门之四 下一篇:Zend Framework和Struts2