DAO:package com.gxjs.DAO;import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;import util.DBException;
import util.DataBaseDAO;import com.gxjs.model.CheckMonM;public class CheckMonDAO {
public ArrayList getCheckMon(String beginDay,String endDay, DataBaseDAO dataBaseDAO) throws DBException{
ArrayList arrayList= new ArrayList();
CheckMonM checkMonM;
//建立结果集
ResultSet rs=null;
String strSql="select a.raw_file_name,a.record_count record_count1,a.record_normal record_normal1,b.record_count record_count2,b.record_normal record_normal2,c.record_count record_normal3,c.deal_time from log_analyse_sum a, log_billing_sum b, log_sum c ";
strSql=strSql + " where c.deal_time between TO_CHAR(TO_DATE('"+beginDay+"', 'YYYY-MM-DD'), 'YYYYMMDD') AND";
strSql=strSql + " TO_CHAR(TO_DATE('"+endDay+"', 'YYYY-MM-DD'), 'YYYYMMDD') and rownum<100 ";
System.out.println(strSql);
//取得结果集
rs=dataBaseDAO.executeQuery(strSql);
try {
while(rs.next()){
checkMonM=new CheckMonM();
checkMonM.setRawfileName(rs.getString("raw_file_name"));
checkMonM.setRecordCount1(rs.getLong("record_count1"));
checkMonM.setRecordNormal1(rs.getLong("record_normal1"));
checkMonM.setRecordCount2(rs.getLong("record_count2"));
checkMonM.setRecordNormal2(rs.getLong("record_normal2"));
checkMonM.setRecordCount3(rs.getLong("record_normal3"));
checkMonM.setDealTime(rs.getString("deal_time"));
arrayList.add(checkMonM);
}
//关闭结果集
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
//异常时需关闭连接防止占用锁
dataBaseDAO.disConn();
throw new DBException(strSql + "执行结果集出现错误:" + e.toString(), e);
}
return arrayList;
}
}Servlet:package com.gxjs.servlet;import java.io.IOException;
import java.util.ArrayList;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import util.DBException;
import util.DataBaseDAO;
import util.DataBaseDAOImpl;import com.gxjs.DAO.CheckMonDAO;public class CheckMon extends HttpServlet { protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(req, resp);
} protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
//String hostName=req.getParameter("host_name");
//String threadId=req.getParameter("thread_id");
//String rawMscNum=req.getParameter("raw_msc_num");
String beginDay=req.getParameter("qry__begin_day");
String endDay=req.getParameter("qry__end_day");
DataBaseDAO dataBaseDAO=new DataBaseDAOImpl();
CheckMonDAO checkMonDAO=new CheckMonDAO();
ArrayList arrayList=new ArrayList();
try {
//取得连接
dataBaseDAO.setConn();
//调用DAO
arrayList=checkMonDAO.getCheckMon(beginDay, endDay, dataBaseDAO);
//关闭连接
dataBaseDAO.disConn();
} catch (DBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
req.setAttribute("checkMonList",arrayList);
//System.out.println("getContextPath: "+req.getContextPath());
req.getRequestDispatcher("./backrun/backrunCheckMonRht.jsp").forward(req, resp);
}
}
import java.sql.SQLException;
import java.util.ArrayList;import util.DBException;
import util.DataBaseDAO;import com.gxjs.model.CheckMonM;public class CheckMonDAO {
public ArrayList getCheckMon(String beginDay,String endDay, DataBaseDAO dataBaseDAO) throws DBException{
ArrayList arrayList= new ArrayList();
CheckMonM checkMonM;
//建立结果集
ResultSet rs=null;
String strSql="select a.raw_file_name,a.record_count record_count1,a.record_normal record_normal1,b.record_count record_count2,b.record_normal record_normal2,c.record_count record_normal3,c.deal_time from log_analyse_sum a, log_billing_sum b, log_sum c ";
strSql=strSql + " where c.deal_time between TO_CHAR(TO_DATE('"+beginDay+"', 'YYYY-MM-DD'), 'YYYYMMDD') AND";
strSql=strSql + " TO_CHAR(TO_DATE('"+endDay+"', 'YYYY-MM-DD'), 'YYYYMMDD') and rownum<100 ";
System.out.println(strSql);
//取得结果集
rs=dataBaseDAO.executeQuery(strSql);
try {
while(rs.next()){
checkMonM=new CheckMonM();
checkMonM.setRawfileName(rs.getString("raw_file_name"));
checkMonM.setRecordCount1(rs.getLong("record_count1"));
checkMonM.setRecordNormal1(rs.getLong("record_normal1"));
checkMonM.setRecordCount2(rs.getLong("record_count2"));
checkMonM.setRecordNormal2(rs.getLong("record_normal2"));
checkMonM.setRecordCount3(rs.getLong("record_normal3"));
checkMonM.setDealTime(rs.getString("deal_time"));
arrayList.add(checkMonM);
}
//关闭结果集
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
//异常时需关闭连接防止占用锁
dataBaseDAO.disConn();
throw new DBException(strSql + "执行结果集出现错误:" + e.toString(), e);
}
return arrayList;
}
}Servlet:package com.gxjs.servlet;import java.io.IOException;
import java.util.ArrayList;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import util.DBException;
import util.DataBaseDAO;
import util.DataBaseDAOImpl;import com.gxjs.DAO.CheckMonDAO;public class CheckMon extends HttpServlet { protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(req, resp);
} protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
//String hostName=req.getParameter("host_name");
//String threadId=req.getParameter("thread_id");
//String rawMscNum=req.getParameter("raw_msc_num");
String beginDay=req.getParameter("qry__begin_day");
String endDay=req.getParameter("qry__end_day");
DataBaseDAO dataBaseDAO=new DataBaseDAOImpl();
CheckMonDAO checkMonDAO=new CheckMonDAO();
ArrayList arrayList=new ArrayList();
try {
//取得连接
dataBaseDAO.setConn();
//调用DAO
arrayList=checkMonDAO.getCheckMon(beginDay, endDay, dataBaseDAO);
//关闭连接
dataBaseDAO.disConn();
} catch (DBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
req.setAttribute("checkMonList",arrayList);
//System.out.println("getContextPath: "+req.getContextPath());
req.getRequestDispatcher("./backrun/backrunCheckMonRht.jsp").forward(req, resp);
}
}
<%@ page contentType="text/html; charset=GBK" %>
<%@page import="com.gxjs.model.CheckMonM"%>
<%@page import="java.util.ArrayList"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>系统</title>
<SCRIPT language=JavaScript src="/gxjs/js nlayer.js"></SCRIPT>
<SCRIPT language=javascript src="/gxjs/js/SmartMenuToc.js"></SCRIPT>
<SCRIPT language=javascript src="/gxjs/js/js.js"></SCRIPT>
<script type="text/JavaScript" src="/gxjs/js/date/scw.js"></script>
<script type="text/javascript" src="/gxjs/js/poslib.js"></script>
<script type="text/javascript" src="/gxjs/js/scrollbutton.js"></script>
<script type="text/javascript" src="/gxjs/js/menu4.js"></script>
<link rel="stylesheet" href="/gxjs/css/css.css" type="text/css">
</head>
<body>
<form name="tableQryForm" action="/gxjs/checkMonServlt" method="POST" >
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" width="100%">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr> </tr>
<tr>
<td height="5" colspan="2"></td>
</tr>
<tr>
<td colspan="2"> <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" class="squareB" >
<tr>
<td><img src="/gxjs/images/square_corner_1.gif" width="5" height="5"></td>
<td background="/gxjs/images/square_line_1.gif"></td>
<td><img src="/gxjs/images/square_corner_2.gif" width="5" height="5"></td>
</tr>
<tr>
<td background="/gxjs/images/square_line_2.gif"></td>
<td width="100%" height="100%" valign="top">
<table width="100%" border="0">
<tr>
<td width="9%"></td>
<td class="query-input-label"></td>
<td width="16%"></td>
<td width="18%" align="center" class="query-input-label"></td>
</tr>
<tr>
<td class="query-input-label" width="9%"></td>
<td class="query-input-label" width="16%">起始日期</td>
<td width="18%"><input type="text" size="16" name="qry__begin_day"
onClick="scwShow(this,this);">
</td>
<td class="query-input-label" width="9%">终止日期</td>
<td width="16%"><input type="text" size="16" name="qry__end_day"
onClick="scwShow(this,this);">
</td>
<td width="10%" align="center" class="query-input-label"><input class="button" onMouseOver="switchClass(this)" onMouseOut="switchClass(this)" value="查询" type="Submit" name=Submit></td>
<td width="18%" align="center" class="query-input-label">
<input type="reset" name="Submit2" class="button" onMouseOver="switchClass(this)" onMouseOut="switchClass(this)" value=重置 type=reset name=Submit2>
</td>
</tr>
</table></td>
<td background="/gxjs/images/square_line_3.gif"></td>
</tr>
<tr>
<td height="6"><img src="/gxjs/images/square_corner_3.gif" width="5" height="5"></td>
<td background="/gxjs/images/square_line_4.gif"></td>
<td><img src="/gxjs/images/square_corner_4.gif" width="5" height="5"></td>
</tr>
</table> </td>
</tr>
<tr>
<td height="5"></td>
</tr>
</table>
</td>
</tr>
</table>
</form><form name="tableListForm" action="" method="POST">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="100%">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="9"><img src="/gxjs/images/sh/corner_1.gif" width="9" height="21"></td>
<td class="lable-bg" nowrap><B>监控稽核列表</B></td>
<td width="27"><img src="/gxjs/images/sh/corner_2.gif" width="27" height="21"></td>
<td valign="bottom" class="side-3" > </td>
</tr>
</table></td>
</tr>
<tr>
<td class="side-5"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><table width="100%" height="8" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="100%" class="report-desc" align="right"><table width="100%">
</table>
</td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="100%" border="0" cellpadding="0" cellspacing="0" class="table">
<tr class="table-th">
<td class="table-item" align="center" width="15%">文件名</td>
<td class="table-item" align="center" width="14%">输入记录</td>
<td class="table-item" align="center" width="14%">输出记录</td>
<td class="table-item" align="center" width="14%"> 输入记录</td>
<td class="table-item" align="center" width="14%"> 输出记录</td>
<td class="table-item" align="center" width="14%">总入库记录</td>
<td class="table-item" align="center" width="15%">处理时间</td>
</tr>
<!--循环取出值显示--> <%
ArrayList arrayList=new ArrayList();
CheckMonM checkMonM=new CheckMonM();
if(request.getAttribute("checkMonList")!= null){
arrayList=(ArrayList) request.getAttribute("checkMonList");
}
if (arrayList.size()==0 ||arrayList == null){
out.println("<tr class=\"table-trb\">");
out.println(" <td class=\"table-item\" align=\"center\" colspan=\"20\"><b><font color=\"red\">当前条件没有记录</font></b></td>");
out.println("</tr>");
}else{
for(int i=0;i<arrayList.size();i++){
checkMonM=(CheckMonM)arrayList.get(i);
out.println("<tr class=\"table-trb\">");
out.println(" <td class=\"table-item\" align=\"center\">"+checkMonM.getRawfileName()+"</td>");
out.println(" <td class=\"table-item\" align=\"center\">"+checkMonM.getRecordCount1()+"</td>");
out.println(" <td class=\"table-item\" align=\"center\">"+checkMonM.getRecordNormal1()+"</td>");
out.println(" <td class=\"table-item\" align=\"center\">"+checkMonM.getRecordCount2()+"</td>");
out.println(" <td class=\"table-item\" align=\"center\">"+checkMonM.getRecordNormal2()+"</td>");
out.println(" <td class=\"table-item\" align=\"center\">"+checkMonM.getRecordCount3()+"</td>");
out.println(" <td class=\"table-item\" align=\"center\">"+checkMonM.getDealTime()+"</td>");
}
}
%>
</table></td>
</tr>
</table>
</body>
</html>请弄个分页,谢谢!
* s2jsp.dlc.ch02.biz.MessageBiz.java
* 2007-08-10
* 留言业务类
*/
package s2jsp.dlc.ch02.biz;import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;import s2jsp.dlc.ch02.dao.MessageDao;
import s2jsp.dlc.ch02.entity.Message;public class MessageBiz {
private MessageDao messageDao = new MessageDao(); // 获得留言数据访问对象
/**
* 保存留言
* @param message
* @return
*/
public int save(Message message){
String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); // 取得日期时间
message.setPostTime(time);
return messageDao.save(message);
}
/**
* 查询留言
* @param page
* @return
*/
public List listByPage(int page){
return messageDao.listByPage(page);
}
}
/*
* s2jsp.dlc.ch02.dao.MessageDao.java
* 2007-08-10
* 留言的数据库访问类
*/
package s2jsp.dlc.ch02.dao;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.ArrayList;import s2jsp.dlc.ch02.entity.Message;public class MessageDao {
public final static String driver = "sun.jdbc.odbc.JdbcOdbcDriver"; // 数据库驱动
public final static String url = "jdbc:odbc:grade2"; // url
public final static String dbName = "sa"; // 数据库用户名
public final static String dbPass = "111"; // 数据库密码
private Connection conn = null; // 数据库连接
private PreparedStatement pstmt = null; // 创建PreparedStatement对象
private ResultSet rs = null; // 创建结果集对象 /**
* 保存一条留言
* @param message
* @return
*/
public int save(Message message){
int result = 0;
String sql = "insert into TBL_MESSAGE(message,author,postTime) values(?,?,?)";
try {
conn = this.getConn(); // 获取数据库链接
pstmt = conn.prepareStatement(sql); // 获取PreparedStatement对象
pstmt.setString(1, message.getMessage());
pstmt.setString(2, message.getAuthor());
pstmt.setString(3, message.getPostTime());
result = pstmt.executeUpdate(); // 执行sql
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally{
this.closeAll(conn, pstmt, rs);
}
return result;
} /**
* 查询全部留言
* @param uid
* @return
*/
public List listByPage(int page) {
List list = new ArrayList();
int rowBegin = 0; // 开始行数,表示每页第一条记录在数据库中的行数
if( page > 1 ) {
rowBegin = 10 * (page-1); // 按页数取得开始行数,设每页可以显示10条留言
}
String sql = "select top 10 * from TBL_MESSAGE " +
"where id not in(select top "+rowBegin+" id from TBL_MESSAGE order by id) " +
"order by id";
try {
conn = this.getConn(); // 获取数据库链接
pstmt = conn.prepareStatement(sql); // 获取PreparedStatement对象
rs = pstmt.executeQuery(); // 执行sql取得查询结果集
while(rs.next()) {
Message message = new Message();
message.setId(rs.getInt("id"));
message.setMessage(rs.getString("message"));
message.setAuthor(rs.getString("author"));
message.setPostTime(rs.getString("postTime"));
list.add(message);
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally{
this.closeAll(conn, pstmt, rs);
}
return list;
} /**
* 得到数据库连接
* @throws ClassNotFoundException
* @throws SQLException
* @return 数据库连接
*/
public Connection getConn() throws ClassNotFoundException, SQLException{
Class.forName(driver); //注册驱动
return DriverManager .getConnection(url,dbName,dbPass); //获得数据库连接并返回
}
/**
* 释放资源
* @param conn 数据库连接
* @param pstmt PreparedStatement对象
* @param rs 结果集
*/
public void closeAll( Connection conn, PreparedStatement pstmt, ResultSet rs ) {
/* 如果rs不空,关闭rs */
if(rs != null){
try { rs.close();} catch (SQLException e) {e.printStackTrace();}
}
/* 如果pstmt不空,关闭pstmt */
if(pstmt != null){
try { pstmt.close();} catch (SQLException e) {e.printStackTrace();}
}
/* 如果conn不空,关闭conn */
if(conn != null){
try { conn.close();} catch (SQLException e) {e.printStackTrace();}
}
}
}
* s2jsp.dlc.ch02.entity.Message
* 2007-08-13
* 留言类
*/
package s2jsp.dlc.ch02.entity;public class Message {
private int id; // 留言id
private String message; // 留言内容
private String author; // 作者
private String postTime; // 发布时间
/**
* @return id
*/
public int getId() {
return id;
}
/**
* @param id 要设置的 id
*/
public void setId(int id) {
this.id = id;
}
/**
* @return message
*/
public String getMessage() {
return message;
}
/**
* @param message 要设置的 message
*/
public void setMessage(String message) {
this.message = message;
}
/**
* @return author
*/
public String getAuthor() {
return author;
}
/**
* @param author 要设置的 author
*/
public void setAuthor(String author) {
this.author = author;
}
/**
* @return postTime
*/
public String getPostTime() {
return postTime;
}
/**
* @param postTime 要设置的 postTime
*/
public void setPostTime(String postTime) {
this.postTime = postTime;
}
}
google去找资料比这里快多了.
说实话,做个分页很快,但是,与看完你的代码的时间相比,太浪费时间了,,,
LX看看有谁有空?