JSP 分页查询关键代码
1. 连接数据库的基类:
package mons;
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) {
}
}
return conn;
// TODO Auto-generated catch block e.printStackTrace();
// TODO Auto-generated catch block e.printStackTrace();
} catch (SQLException e) {