日期:2014-05-16  浏览次数:20506 次

JSP+Servlet+JDBC实现数据分页

环境

 

MyEclipse 8.6 + MySQL 5.1 + MySQL命令行工具+ JDK 1.6

 

问题

 

JSP+Servlet+JDBC实现分页

 

解决

 

第一步 创建数据库

 

以下为数据库导出脚本。

 

test.sql

 

-- MySQL dump 10.13  Distrib 5.1.43, for Win32 (ia32)
--
-- Host: localhost    Database: test
-- ------------------------------------------------------
-- Server version	5.1.43-community

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `test`
--

DROP TABLE IF EXISTS `test`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `test` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(20) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=98 DEFAULT CHARSET=gbk;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `test`
--

LOCK TABLES `test` WRITE;
/*!40000 ALTER TABLE `test` DISABLE KEYS */;
INSERT INTO `test` VALUES (1,'test1'),(2,'test2'),(3,'test3'),(4,'test4'),(5,'test5'),(6,'test6'),(7,'test7'),(8,'test8'),(9,'test9'),(10,'test10'),(11,'test1'),(12,'test2'),(13,'test3'),(14,'test4'),(15,'test5'),(16,'test6'),(17,'test7'),(18,'test8'),(19,'test9'),(20,'test10'),(26,'test1'),(27,'test2'),(28,'test3'),(29,'test4'),(30,'test5'),(31,'test6'),(32,'test7'),(33,'test8'),(34,'test9'),(35,'test10'),(36,'test1'),(37,'test2'),(38,'test3'),(39,'test4'),(40,'test5'),(41,'test6'),(42,'test7'),(43,'test8'),(44,'test9'),(45,'test10'),(57,'test1'),(58,'test2'),(59,'test3'),(60,'test4'),(61,'test5'),(62,'test6'),(63,'test7'),(64,'test8'),(65,'test9'),(66,'test10'),(67,'test1'),(68,'test2'),(69,'test3'),(70,'test4'),(71,'test5'),(72,'test6'),(73,'test7'),(74,'test8'),(75,'test9'),(76,'test10'),(77,'test1'),(78,'test2'),(79,'test3'),(80,'test4'),(81,'test5'),(82,'test6'),(83,'test7'),(84,'test8'),(85,'test9'),(86,'test10'),(87,'test1'),(88,'test2'),(89,'test3'),(90,'test4'),(91,'test5'),(92,'test6'),(93,'test7'),(94,'test8'),(95,'test9'),(96,'test10'),(97,'900');
/*!40000 ALTER TABLE `test` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2013-01-22 11:17:45


 

 第二步 封装实体类

 

Test.java

 

package com.wgb.bean;

public class Test {
	private int id;
	private String nam