纯JSP分页代码之sqlserver2005/2008
上一篇分页文章,是用于mysql,稍微修改下,用于Sqlserver2005/2008,没有异常处理。没有考虑性能等。
现将代码贴出,以供初学者参考:
注:邀月使用环境Eclipse 3.4.2+Tomcat 6.18+Sqlserver2005 sp3调试成功。
页面pagelistDemo.jsp内容:
Code
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
//连接字符串
String url = "jdbc:sqlserver://" + Globals.Server
+ ";databaseName=" + Globals.DbName;
Class.forName(Globals.driverName).newInstance();
Connection connection = DriverManager.getConnection(url,
Globals.username, Globals.pwd);
Statement statement = connection.createStatement();
//每页显示记录数
int PageSize = 10;
int StartRow = 0; //开始显示记录的编号
int PageNo = 0;//需要显示的页数
int CounterStart = 0;//每页页码的初始值
int CounterEnd = 0;//显示页码的最大值
int RecordCount = 0;//总记录数;
int MaxPage = 0;//总页数
int PrevStart = 0;//前一页
int NextPage = 0;//下一页
int LastRec = 0;
int LastStartRecord = 0;//最后一页开始显示记录的编号
//获取需要显示的页数,由用户提交
if (request.getParameter("PageNo") == null) {&n
相关文档:
MS SQL Server查询优化方法
查询速度慢的原因很多,常见如下几种
1、没有索引或者没有用到索引(这是查询慢最常见的问题,是程序设计的缺陷)
2、I/O吞吐量小,形成了瓶颈效应。
& ......
此实现共分三个文件,即:CreatImage.java 生成图像流的类,提供用于生成图片流的方法;images.jsp 图片包装,用于将图片加入到response输出流中;login.jsp 调用前面的jsp,显示验证码。
CreatImage.java 类:
3 import java.awt.Color;
4 import java.awt.Font;
5 import java.awt.Graphics;
6 im ......
注意:jsp:useBean动作,用表单为Bean的属性赋值时,也就是jsp:setProperty动作直接收请求中表单的信息为使用的Bean的属性进行赋值,也就是说jsp:useBean和jsp:setProperty不能够出现在为这个Bean的属性赋值的form表单的页面上。
JSP的异常处理
<%@page errorPage="xxx.jsp"%> 指定本页面出现异常后要转到的页面
& ......
//运行图:
//连接字符串
String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;
Class.forName(driverName).newInstance();
Connection connection=DriverManager.getConnection(url);
Statement statement = connection.createStatement();
//每页显示记录数
int PageSize ......