<%@ page contenttype="text/html;charset=gb2312"%>
<%
//变量声明
java.sql.connection sqlcon; //数据库连接对象
java.sql.statement sqlstmt; //sql语句对象
java.sql.resultset sqlrst; //结果集对象
java.lang.string strcon; //数据库连接字符串
java.lang.string strsql; //sql语句
int intpagesize; //一页显示的记录数
int introwcount; //记录总数
int intpagecount; //总页数
int intpage; //待显示页码
int rowi;
java.lang.string strpage;
int i,j,k;
rowi=0;
string pagesize = (string) session.getvalue("pagesize");
//if(pagesize!=null){
intpagesize=integer.parseint(pagesize);
strpage = request.getparameter("page"); //取得待显示页码
if(strpage==null){
//表明在querystring中没有page这一个参数,此时显示第一页数据
intpage = 1;
} else{
//将字符串转换成整型
intpage = java.lang.integer.parseint(strpage);
if(intpage<1) intpage = 1; }
//装载jdbc驱动程序
class.forname("com.microsoft.jdbc.sqlserver.sqlserverdriver");
//设置数据库连接字符串
strcon ="jdbc:microsoft:sqlserver://localhost:1433;databasename=sunmoon" ;
//连接数据库
sqlcon = java.sql.drivermanager.getconnection(strcon,"sa","sa");
//创建sql语句对象
sqlstmt = sqlcon.createstatement();
//获取记录总数
string companyname = (string) session.getvalue("companyname");
if ("全部客户".equals(companyname))
{
strsql = "select count(*) from customer";
}
else
{
strsql = "select count(*) from customer where 客户名称='"+companyname+"'";
}
//strsql = "select count(*) from loadweight where 收货方='"+company+"' ";
sqlrst = sqlstmt.executequery(strsql);
//执行sql语句并取得结果集
sqlrst.next(); //记录集刚打开的时候,指针位于第一条记录之前
introwcount = sqlrst.getint(1);
sqlrst.close(); //关闭结果集
//记算总页数
intpagecount = (introwcount+intpagesize-1) / intpagesize;
//调整待显示的页码
if(intpage>intpagecount) intpage = intpagecount;
//设置获取数据sql语句
//strsql = "select * from loadweight where 收货方='广州世经'";
{
if ("全部客户".equals(companyname))
{
strsql = "select * from customer order by 客户序号";
}
else
{
strsql = "select * from customer where 客户名称='"+companyname+"' order by 客户序号";
}
//strsql = strsql+" and 时间 between '2003-3-1' and '2003-4-1' ";
//out.println(strsql);
}
//执行sql语句并取得结果集
sqlrst = sqlstmt.executequery(strsql);
//将记录指针定位到待显示页的第一条记录上
i = (intpage-1) * intpagesize;
for(j=0;j<i;j++) sqlrst.next(); %>
<html>
<link href="../../css/style.css" rel="stylesheet" type="text/css">
<head>
<title>数据库查询系统</title>
</head>
<script language=javascript>
function selectrow(ocurrent)
{
ocurrent.style.backgroundcolor="ccccff";
for(var i = 0; i < document.all('t1').rows.length;i++)
{
if(t1.rows[i] != ocurrent) t1.rows[i].style.backgroundcolor="ffffff";
}
}
function moveto(page)
{
form1.action = "/sunmoon/jsp/inside/customer/customdbqueary.jsp?page=" + page;
form1.method = "post";
form1.submit();
}
function printpage() { print(document); }
</script>
<body>
<table width="90%" border="0" align="center">
<tr>
<td nowrap>
<div align="center"><strong><font color="#660099" size="4" face="宋体">系统查询结果</font></strong></div></td>
</tr>
</table>
<p align=center><strong></strong></p>
<table width=90% border=0 align=center cellpadding=0 cellspacing=0 id=t1>
<tr>
<td width="104" height="16" align=center nowrap bgcolor="#ffffcc"> <div align="left"><font color="#0000ff">编号</font></div></td>
<td width=60 align=center nowrap bgcolor="#ffffcc"> <div align="left"><font color="#0000ff">客户名称</font></div></td>
<td width="103" align=center nowrap bgcolor="#ffffcc"> <div align="left"><font color="#0000ff">账号</font></div></td>
<td width="117" align=center nowrap bgcolor="#ffffcc"> <div align="left"><font color="#0000ff">税号</font></div></td>
<td width="117" align=center nowrap bgcolor="#ffffcc"> <div align="left"><font color="#0000ff">开户行</font></div></td>
<td width="86" align=center nowrap bgcolor="#ffffcc"> <div align="left"><font color="#0000ff">电话号码</font></div></td>
<td width="100" align=center nowrap bgcolor="#ffffcc"> <div align="left"><font color="#0000ff">详单</font></div></td>
</tr>
<%
//显示数据
i = 0;
while(i<intpagesize && sqlrst.next()){rowi=rowi+1; %>
<% if(rowi%2==0)
{
out.print("<tr bgcolor=#ccccff onmouseover=selectrow(this)>");
}
else
{
//out.print("<tr onmouseover="selectrow(this)"">;
}
%>
<td height="18" valign="top" nowrap><%=sqlrst.getstring("客户序号")%></td>
<td valign="top" nowrap><%=sqlrst.getstring("客户名称")%></td>
<td nowrap><%=sqlrst.getstring("账号")%></td>
<td nowrap><%=sqlrst.getstring("税号")%></td>
<td nowrap><%=sqlrst.getstring("开户行")%></td>
<td nowrap><%=sqlrst.getstring("电话号码")%></td>
<% string customname=sqlrst.getstring("客户序号");
out.print("<td width=9% nowrap><a href=customsingle.jsp?customer="+customname+">详单</a></td>");
%>
</tr>
<% i++; } %>
<tr bgcolor="#ffccff">
<td height="18" colspan=7 align=right> <div align="right"><font color="#0000ff">第<%=intpage%>页 共<%=intpagecount%>页 <a href="customdbqueary.jsp?page=1">首页</a>
<%if(intpage>1){%>
<a href="customdbqueary.jsp?page=<%=intpage-1%>">上一页</a>
<%
}
%>
<%if(intpage<intpagecount){%>
<a href="customdbqueary.jsp?page=<%=intpage+1%>">下一页</a>
<%
}
%>
<a href="customdbqueary.jsp?page=<%=intpagecount%>">尾页 </a>
</font> </div></td>
<td> </td>
</tr>
<tr align="right">
<td height="22" colspan="8" align="right" valign="top" nowrap bgcolor="#ffffff">
<form name="form1" method="post" action="" >
<font color="#0000ff">转到第
<input type=text name=page size=2 maxlength=3 value='' style='height:16;vertical-align:8%'>
页
<input class=buttonface type=submit value='go'>
</font> </form></td>
</tr>
<tr align="right">
<td height="22" colspan="8" align="right" valign="top"> <input class=buttonface value="打印" type="button" onclick="printpage()"></td>
</tr>
</table>
</body>
</html>
<%
//关闭结果集
sqlrst.close();
//关闭sql语句对象
sqlstmt.close();
//关闭数据库
sqlcon.close();
%>
国内最大的酷站演示中心!
新闻热点
疑难解答