给你一段代码:我实现了的:
/**Access数据库连接*/
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc:odbc:gogoSource";
Connection con = null;
Statement Stmt = null;
Connection tempCon = null;
Statement tempStmt = null;
ResultSet rsFirst = null;
ResultSet rsTotal = null;
ResultSet rs = null;
String sql = null;
try
{
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e)
{
out.println("数据库连接初始化错误"+e.getMessage());
}
try
{
if (addFlag.equals("Yes"))
{
con = DriverManager.getConnection(url,"","");
Stmt = con.createStatement();
sql = "select Id from Tb_monthCollection where collYearMonth=(DateValue('"+endDate+"')-1)";
rsFirst = Stmt.executeQuery(sql);
if(rsFirst.next())
{
tempCon = DriverManager.getConnection(url,"","");
tempStmt = tempCon.createStatement();
sql = "delete from Tb_monthCollection where collYearMonth=(DateValue('"+endDate+"')-1)";
tempStmt.executeUpdate(sql);
tempStmt.close();
tempCon.close();
}
rsFirst.close();
Stmt.close();
con.close();
tempCon = DriverManager.getConnection(url,"","");
tempStmt = tempCon.createStatement();
sql = "Insert into Tb_monthCollection (collYearMonth,payOutKindId,MonthCharge,re) ";
sql = sql + " select (DateValue('"+endDate+"')-1), payOutKindId,sum(Charge),'"+re+"'";
sql = sql + " from Tb_payOut where occurDate>=DateValue('"+startDate+"') and occurDate<DateValue('"+endDate+"')" ;
sql = sql + " group by payOutKindId ";
tempStmt.executeUpdate(sql);
tempStmt.close();
tempCon.close();
}
}
catch(SQLException e)
{
out.println("出错信息:"+e.toString());
}
%>
<table border="0" align="center">
<tr>
<td>
<%
try
{
con = DriverManager.getConnection(url,"","");
Stmt = con.createStatement();
if (addFlag.equals("No"))
{
sql = "select a.Id,a.collYearMonth,b.payOutKindName,a.MonthCharge,a.re from Tb_monthCollection a,tb_payOutKind b where a.payOutKindId=b.payOutKindId";
sql = sql + " and a.collYearMonth>=DateValue('"+startDate+"') and a.collYearMonth<DateValue('"+endDate+"') and a.payOutKindId like '%"+payOutKindId+"%' order by a.collYearMonth desc";
}
else
{
sql = "select a.Id,a.collYearMonth,b.payOutKindName,a.MonthCharge,a.re from Tb_monthCollection a,tb_payOutKind b where a.payOutKindId=b.payOutKindId order by a.collYearMonth desc";
}
rsTotal = Stmt.executeQuery(sql);
//System.out.println(sql);
int count=0;
int pagecount=0;
int pages=0;
int pagesize=10;
float totalCout = 0; //总花费额
while(rsTotal.next())
{
count++;
totalCout = totalCout + rsTotal.getFloat(4);
}
rsTotal.close();
if(count%pagesize==0)
pagecount = count/pagesize;
else
pagecount = count/pagesize+1;
String strpages = request.getParameter("pages");
//out.println("strpages: "+strpages);
if((strpages==null)||strpages.equals(""))
pages=1;
else
{
pages = new Integer(strpages).intValue();
if(pages<=0)
pages=1;
}
rs = Stmt.executeQuery(sql);
int i;
for(i=1;i<=(pages-1)*pagesize;i++)
{
rs.next();
}
%>
<form name="submit_frm" method="post" target="main" >
<table border="0" align="center">
<tr>
<td>
<table border="0" align="center" style="font-size:10pt">
<tr>
<td align="center">
<font style="font-size:18" color="green">公司支出汇总表</font>
<br><br>
<table id="tbl_select" border="1" cellspacing="0" cellpadding="0" style="font-size:10pt" algin="center">
<tr align="center" bgcolor="#D4D0C8">
<!--<td>编号</td>-->
<td width="80px">汇总年月</td>
<td width="80px">支出类型</td>
<td width="140px">月总费用</td>
<td width="200px">备注</td>
</tr>
<%
for(i=1;i<=pagesize;i++)
{
if(rs.next())
{
%>
<tr onClick="javascript:selectedRow(<%=i%>)">
<!--<td><%=rs.getInt(1)%></td>-->
<td align="center"><%=(rs.getString(2)).substring(0,7)%> </td>
<td><%=rs.getString(3)%> </td>
<td align="right"><%=rs.getFloat(4)%> </td>
<td><%=rs.getString(5)%> </td>
</tr>
<%
}
}
%>
<tr >
<td colspan="2" align="right">总花费额:</td>
<td colspan="2" align="left"><%=totalCout%>元</td>
</tr>
</table>
/**Access数据库连接*/
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc:odbc:gogoSource";
Connection con = null;
Statement Stmt = null;
Connection tempCon = null;
Statement tempStmt = null;
ResultSet rsFirst = null;
ResultSet rsTotal = null;
ResultSet rs = null;
String sql = null;
try
{
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e)
{
out.println("数据库连接初始化错误"+e.getMessage());
}
try
{
if (addFlag.equals("Yes"))
{
con = DriverManager.getConnection(url,"","");
Stmt = con.createStatement();
sql = "select Id from Tb_monthCollection where collYearMonth=(DateValue('"+endDate+"')-1)";
rsFirst = Stmt.executeQuery(sql);
if(rsFirst.next())
{
tempCon = DriverManager.getConnection(url,"","");
tempStmt = tempCon.createStatement();
sql = "delete from Tb_monthCollection where collYearMonth=(DateValue('"+endDate+"')-1)";
tempStmt.executeUpdate(sql);
tempStmt.close();
tempCon.close();
}
rsFirst.close();
Stmt.close();
con.close();
tempCon = DriverManager.getConnection(url,"","");
tempStmt = tempCon.createStatement();
sql = "Insert into Tb_monthCollection (collYearMonth,payOutKindId,MonthCharge,re) ";
sql = sql + " select (DateValue('"+endDate+"')-1), payOutKindId,sum(Charge),'"+re+"'";
sql = sql + " from Tb_payOut where occurDate>=DateValue('"+startDate+"') and occurDate<DateValue('"+endDate+"')" ;
sql = sql + " group by payOutKindId ";
tempStmt.executeUpdate(sql);
tempStmt.close();
tempCon.close();
}
}
catch(SQLException e)
{
out.println("出错信息:"+e.toString());
}
%>
<table border="0" align="center">
<tr>
<td>
<%
try
{
con = DriverManager.getConnection(url,"","");
Stmt = con.createStatement();
if (addFlag.equals("No"))
{
sql = "select a.Id,a.collYearMonth,b.payOutKindName,a.MonthCharge,a.re from Tb_monthCollection a,tb_payOutKind b where a.payOutKindId=b.payOutKindId";
sql = sql + " and a.collYearMonth>=DateValue('"+startDate+"') and a.collYearMonth<DateValue('"+endDate+"') and a.payOutKindId like '%"+payOutKindId+"%' order by a.collYearMonth desc";
}
else
{
sql = "select a.Id,a.collYearMonth,b.payOutKindName,a.MonthCharge,a.re from Tb_monthCollection a,tb_payOutKind b where a.payOutKindId=b.payOutKindId order by a.collYearMonth desc";
}
rsTotal = Stmt.executeQuery(sql);
//System.out.println(sql);
int count=0;
int pagecount=0;
int pages=0;
int pagesize=10;
float totalCout = 0; //总花费额
while(rsTotal.next())
{
count++;
totalCout = totalCout + rsTotal.getFloat(4);
}
rsTotal.close();
if(count%pagesize==0)
pagecount = count/pagesize;
else
pagecount = count/pagesize+1;
String strpages = request.getParameter("pages");
//out.println("strpages: "+strpages);
if((strpages==null)||strpages.equals(""))
pages=1;
else
{
pages = new Integer(strpages).intValue();
if(pages<=0)
pages=1;
}
rs = Stmt.executeQuery(sql);
int i;
for(i=1;i<=(pages-1)*pagesize;i++)
{
rs.next();
}
%>
<form name="submit_frm" method="post" target="main" >
<table border="0" align="center">
<tr>
<td>
<table border="0" align="center" style="font-size:10pt">
<tr>
<td align="center">
<font style="font-size:18" color="green">公司支出汇总表</font>
<br><br>
<table id="tbl_select" border="1" cellspacing="0" cellpadding="0" style="font-size:10pt" algin="center">
<tr align="center" bgcolor="#D4D0C8">
<!--<td>编号</td>-->
<td width="80px">汇总年月</td>
<td width="80px">支出类型</td>
<td width="140px">月总费用</td>
<td width="200px">备注</td>
</tr>
<%
for(i=1;i<=pagesize;i++)
{
if(rs.next())
{
%>
<tr onClick="javascript:selectedRow(<%=i%>)">
<!--<td><%=rs.getInt(1)%></td>-->
<td align="center"><%=(rs.getString(2)).substring(0,7)%> </td>
<td><%=rs.getString(3)%> </td>
<td align="right"><%=rs.getFloat(4)%> </td>
<td><%=rs.getString(5)%> </td>
</tr>
<%
}
}
%>
<tr >
<td colspan="2" align="right">总花费额:</td>
<td colspan="2" align="left"><%=totalCout%>元</td>
</tr>
</table>
解决方案 »
- 用Maven创建的web项目,是否可以打包成war包,然后让在tomcat里跑呢?
- 请问SQL语句,存储过程,索引的区别?
- 谁知道网站的免费域名,想弄个个人网站,还有网站是怎么上传的
- 很奇怪的问题,为什么接受不到request阿?
- 哪位高僧可以指点如何通过电脑发送手机短信
- CSDN-请各位前辈帮忙看一下晚辈的外包项目,传授一些接私活的经验!!
- 如何在<html:form>里嵌套<html:form>,嵌套<html:form>时submit的逻辑顺序是怎么样的?
- java调用*.dll动态库,高手进入,高分相赠!
- spring quartz为什么tomcat启动后没有马上执行
- 关于java web的相对路径问题!
- 关于WEB打印?
- 我在tomcat\conf\server.xml文件中加了如下代码后,为何tomcat不能正常启动了?
<html>
<head>
<%@ page contentType="text/html;charset=gb2312" %>
<title>会员管理</title>
<link rel=stylesheet href="../style.css" type="text/css">
<script LANGUAGE="javascript">
function newwin(url) {
var newwin=window.open(url,"newwin","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=450");
newwin.focus();
return false;
}
</script>
</head>
<body>
<script LANGUAGE="javascript">
function submit10()
{
self.location.replace("admin_user.jsp")
}
</script>
<jsp:include page="../top.jsp" flush="true"/>
<center><p><h4><font color="blue">会员管理</font></h4></p>
<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="adminBean" scope="page" class="firm.firm" />
<%
//指定行数
int pageLine=10;
int totalRec=0;
int totalSub=0;
int intPage=1;
int i;
if (request.getParameter("page")!=null)
intPage=Integer.parseInt(request.getParameter("page"));try{
ResultSet countrs=null;//取得总记录数
countrs=adminBean.executeQuery("select count(*) as cnt from user where name<>'administrator'");
if (countrs.next())
totalRec=countrs.getInt("cnt");
countrs.close();
adminBean.closeStmt();}
catch(Exception e){
e.printStackTrace();
}//取得总页数
int intPageCount=0;
intPageCount = (totalRec+pageLine-1) / pageLine;
%>
<%
ResultSet RS = adminBean.executeQuery("SELECT * FROM user where name<>'administrator' order by id desc");
String name;
String userid;%>
<table border='1' cellspacing='0' width='500' bgcolor='#d7e3b9' bordercolorlight='#green' bordercolordark='#ECF5FF'>
<tr bgcolor='#c8cc98' align='center'>
<td width='8%'>ID</td>
<td width='14%'>会员名</td>
<td width='8%' >删除</td>
</tr>
<%
if (intPageCount>0)
{
for(i=1;i<=(intPage-1)*pageLine;i++)
RS.next();
for(i=1;i<=pageLine;i++) {
if (RS.next()) { name=RS.getString("name");
userid=RS.getString("id");
%>
<tr>
<td width='8%' align='center'><%=userid%></td>
<td width='14%' align='center'><%=name%></td>
<td width='8%' align='center'><a href="delete.jsp?id=<%=userid%>" onClick="return newwin(this.href);">删除</a></td>
</tr>
<%
}
}
RS.close();
}
%>
<!--以下用于分页显示 -->
<%
out.print("<tr>");
if (intPageCount*pageLine<totalRec)
intPageCount++;
if (intPage>intPageCount )
intPage=intPageCount;
if (intPage < 1 )
intPage=1;
out.print("<form method='POST' name=fPageNum action='admin_user.jsp'>");
out.print("<p align='left'>>>分页 ");
if (intPage<2)
out.print("<font color='999966'>首页 上一页</font> ");
else{
out.print("<a href='admin_user.jsp?page=1'>首页</a> ");
out.print("<a href='admin_user.jsp?page=" + (intPage-1) + "'>上一页</a> " );
}
if( intPage-intPageCount>=0 )
out.print("<font color='999966'>下一页 尾页</font>" );
else{
out.print("<a href='admin_user.jsp?page=" + (intPage+1)+ "'>下一页</a> <a href='admin_user.jsp?page=" + intPageCount + "'>尾页</a>");
}
out.print(" 页次:<strong><font color=red>"+intPage+"</font>/"+intPageCount+"</strong>页 " );
out.print(" 共<b>"+totalRec+"</b>条记录 <b>"+pageLine+"</b>条/页 " );
out.print(" 转到第<input type='text' name='page' size=2 maxlength=10 class=smallInput value="+intPage+">");
out.print("页<input class=buttonface type='submit' value='GO' name='cndok'></span></p></form>" ); out.print("</td>");
out.print("</tr>");
%>
</table></p>
<a href="javascript:window.close();">[关闭]</a>
</center>
<jsp:include page="../bottom.jsp" flush="true"/>
</body>
</html>