<form method="post" action="">
<table>
<%
\\数据库调用过程
rs = stmt.executeQuery("SELECT * FROM 表 order by id desc");
while (rs.next()){
%>
<tr>
 <td>
<%=rs.getString("字段名1")%>
 </td>
<td>
<%=rs.getString("字段名2")%>
 </td>
........
</tr>
<%
rs.next();
}
rs.close();//关闭结果集
stmt.close();//关闭SQL语句对象
con.close();//关闭数据库
%>
</table>
</form>写的匆忙可能有错误。

解决方案 »

  1.   

    //本程序是我做的一项目中的订单查询功能,带有分页和颜色交替功能。//开始分页 
    java.sql.Connection sqlCon; //数据库连接对象 
    java.sql.Statement sqlStmt; //SQL语句对象 
    java.lang.String strCon; //数据库连接字符串 
    int intPageSize; //一页显示的记录数 
    int intRowCount; //记录总数 
    int intPageCount; //总页数 
    int intPage; //待显示页码 
    java.lang.String strPage; 
    int i,j,k; //设置一页显示的记录数 
    intPageSize = 10; //取得待显示页码 
    strPage = request.getParameter("page"); 
    if(strPage==null){
    //表明在QueryString中没有page这一个参数,此时显示第一页数据 
    intPage = 1; 
    } else{
    //将字符串转换成整型 
    intPage = java.lang.Integer.parseInt(strPage); 
    if(intPage<1) intPage = 1; }
    String sqlstr_count="select count(*) from order_info where nickname='"+username+"' and order_day>='"+olddate+"' and order_day<='"+currentdate+"'"; 
    ResultSet rs = dbconn.executeQuery(sqlstr_count); 
    rs.next(); //记录集刚打开的时候,指针位于第一条记录之前 
    intRowCount = rs.getInt(1); 
    rs.close(); //关闭结果集 
    //String linkstr="?dpt_code=" + dpt_code + "&product_type=" + product_type + "&brand_sign=" + brand_sign;
    //linkstr=linkstr + "&orderby=" + orderby + "&pic_sign=" + pic_sign;
    intPageCount = (intRowCount+intPageSize-1) / intPageSize; 
    rs = dbconn.executeQuery(sqlstr);
    //将记录指针定位到待显示页的第一条记录上 
    i = (intPage-1) * intPageSize; %>
    <TABLE align=center border=0 cellPadding=0 cellSpacing=0 width=700>
      <TBODY>
        <TR> 
          <TD height=25><FONT color=#990033><B 
        class=p10>亲爱的 <%=truename%>,您好!<br>
            <br>
            以下是您 
            <select name="period">
              <option>请选择</option>
              <option value="0" <%if (period==0){out.print("selected");}%>>最近3天</option>
              <option value="1" <%if (period==1){out.print("selected");}%>>最近1个星期</option>
              <option value="2" <%if (period==2){out.print("selected");}%>>最近1个月</option>
              <option value="3" <%if (period==3){out.print("selected");}%>>全部</option>
            </select>
            的订单:<br>
            </B></FONT></TD>
        </TR>
        <tr>
        <td>
        
        
       
        <%@ include file="../inc/page_search_order.inc"%>
      
      
    <%for(j=0;j<i;j++) rs.next(); %> 
        
        
        </td>
        </tr>
        
        <TR> 
          
                <TD bgColor=#0080c0> 
          
          <TABLE border=0 cellPadding=4 cellSpacing=1 width="100%">
              <TBODY>
                <TR align=center> 
                  <TD bgColor=#cae9fd>订单号 </TD>
                  <TD bgColor=#cae9fd>订购日期</TD>
                  <TD bgColor=#cae9fd>订购总价(元)</TD>
                  <TD bgColor=#cae9fd>处理状态</TD>
                  <TD bgColor=#cae9fd>是否交易成功?</TD>
                  <TD bgColor=#cae9fd>查看详情</TD>
                </TR>
    <%
    i=0;
    int n=2;
    while (i<intPageSize&&rs.next()){
    String Order_Form_No=rs.getString("order_form_no");
    String Order_Day=rs.getString("order_day");
    String In_Sum=rs.getString("in_sum");
    String bgcolor;
    if (n==2){bgcolor="#ffffff";n=1;}
    else {bgcolor="#efefef";n=2;}
    %><TR align=center bgcolor=<%=bgcolor%>>
    <TD bgColor=<%=bgcolor%>><%=Order_Form_No%></TD>
                  <TD bgColor=<%=bgcolor%>><%=Order_Day%></TD>
                  <TD bgColor=<%=bgcolor%>><%=In_Sum%></TD>
                  <TD bgColor=<%=bgcolor%>>正在</TD>
                  <TD bgColor=<%=bgcolor%>>否</TD>
                  <TD bgColor=<%=bgcolor%>>详情</TD>
                </TR>
                <%
                i=i+1;
                }//end while
                %>
                       
                
              </TBODY>
            </TABLE>
            </TD>
        </TR>
        
        <tr>
        <td>
        <%@ include file="../inc/page_search_order.inc"%>
        </td>
        </tr>
        
      </TBODY>
    </TABLE>其中的page_search_order.inc:<table width=770 height=25 align=center>
    <tr>
    <td align=right>第<%=intPage%>页 共<%=intPageCount%>页 <%if(intPage>1){%><a href="SearchOrderResult.jsp?period=<%=period%>&page=1"><%}%> 首页</font></a><%if(intPage>1){%><a href="SearchOrderResult.jsp?period=<%=period%>&page=<%=intPage-1%>"><%}%> 上一页</a>
    <%if(intPage<intPageCount){%>
    <a href="SearchOrderResult.jsp?period=<%=period%>&page=<%=intPage+1%>"><%}%> 下一页</a> <%if(intPage<intPageCount){%>
    <a href="SearchOrderResult.jsp?period=<%=period%>&page=<%=intPageCount%>"><%}%>尾页</a>
    </td>
    </tr>
    </table>
      

  2.   

    不分页的应该把rs.next()去掉
      

  3.   

    从delphi跑来的,嘻嘻嘻,玩嘛
    嘻嘻嘻