JSP 分页查询关键代码 1. 连接数据库的基类: package com.book.commons; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; public class GetConnection { protected Connection conn = null;//连接字符串 protected PreparedStatement ps = null;//预编译并存储 SQL 指令 protected ResultSet rs = null;//查询结果集 private static final String DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";//加载数据库驱动的字符串 private static final String URL = "jdbc:sqlserver://localhost:1433;databaseName=BOOKDB";//连接数据库的字符串 private static final String USERNAME = "sa";//数据库用户名 private static final String PASSWORD = "accp";//数据库用户密码 /** * 获得数据库连接 * @return */ public Connection getConn() { Connection conn = null; try { Class.forName(DRIVER);//加载数据库驱动 conn = DriverManager.getConnection(URL,USERNAME,PASSWORD);//连接数据库 } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return conn; } /* * 释放资源 */ public void closeAll(){ try { if(rs != null){ rs.close(); } if(ps != null){ ps.close(); } if(conn != null){ conn.close(); } } catch (SQLException e) { e.printStackTrace(); }finally{ conn = null; ps = null; rs = null; } } } 2 . 实体类代码: package com.book.entity; public class Book { private int book_id; private String book_name; private String book_num; private String book_author; private double book_price; private String book_synopsis; private String book_publishTime; public String getBook_author() { return book_author; } public void setBook_author(String book_author) { this.book_author = book_author; } public int getBook_id() { ...