e代剑客——温柔一刀

生活就像海洋,只有意志坚强的人,才能到达彼岸

   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  76 随笔 :: 7 文章 :: 215 评论 :: 0 Trackbacks

 

移动查询

<% @ page contentType = " text/html;charset=GB2312 "   %>
<% @ page import = " java.sql.* "   %>
< HTML >
< BODY >
 
<%  Connection con;
    Statement sql; 
    ResultSet rs;
    try
    {
      Class.forName(
" com.microsoft.jdbc.sqlserver.SQLServerDriver " );
    }
    catch(ClassNotFoundException e)
    {
      out.print(
" 类找不到! " );
    }
    try 
    {  
         con
= DriverManager.getConnection( " jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=testDatabse " , " sa " , " 6599996 " );
         sql
= con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
         rs
= sql.executeQuery( " SELECT * FROM userTable " );
         rs.last();
// 移动到最后一行
         
int  rowNumber = rs.getRow(); // 得到最后一行的行号
         out.print(
" <Table Border> " );
         out.print(
" <TR><td colspan=8 align=center>用户数据(逆序输出,共 " + rowNumber + " 条记录)</td></tr> " );   
         out.print(
" <TR> " );
            out.print(
" <Td width=100 > " + " 用户ID号 " );
            out.print(
" <Td width=50 > " + " 用户名 " );
            out.print(
" <Td width=100> " + " 用户真实姓名 " );
            out.print(
" <Td width=50> " + " 年龄 " );
            out.print(
" <Td width=50> " + " 性别 " );
            out.print(
" <Td width=100> " + " 联系地址 " );
            out.print(
" <Td width=100> " + " 联系电话 " );
            out.print(
" <Td width=100> " + " 添加时间 " );
         out.print(
" </TR> " );
       rs.afterLast();
// 移动到最后一行的后面
       
while (rs.previous())
       { out.print(
" <TR> " );
             out.print(
" <TD > " + rs.getLong( 1 ) + " </TD> " );
             out.print(
" <TD > " + rs.getString( 2 ) + " </TD> " ); 
             out.print(
" <TD > " + rs.getString( 4 ) + " </TD> " );
             out.print(
" <TD > " + rs.getInt( " user_age " ) + " </TD> " ); 
             out.print(
" <TD > " + rs.getString( " user_sex " ) + " </TD> " );
             out.print(
" <TD > " + rs.getString( " user_address " ) + " </TD> " );
             out.print(
" <TD > " + rs.getString( " user_telephone " ) + " </TD> " );
             out.print(
" <TD > " + rs.getString( " add_time " ) + " </TD> " );
        out.print(
" </TR> " ) ; 
        }
       rs.absolute(
2 ); // 移动到第2行
       out.print(
" <TR><td colspan=8 align=center>指定输出第2个用户的数据</td></tr> " );
       out.print(
" <TR> " );
             out.print(
" <TD > " + rs.getLong( 1 ) + " </TD> " );
             out.print(
" <TD > " + rs.getString( 2 ) + " </TD> " ); 
             out.print(
" <TD > " + rs.getString( 4 ) + " </TD> " );
             out.print(
" <TD > " + rs.getInt( " user_age " ) + " </TD> " ); 
             out.print(
" <TD > " + rs.getString( " user_sex " ) + " </TD> " );
             out.print(
" <TD > " + rs.getString( " user_address " ) + " </TD> " );
             out.print(
" <TD > " + rs.getString( " user_telephone " ) + " </TD> " );
             out.print(
" <TD > " + rs.getString( " add_time " ) + " </TD> " );
        out.print(
" </TR> " ) ; 
        out.print(
" </Table> " );
        con.close();
     }
   catch(SQLException e1) 
   {
      out.print(
" SQL异常! " );
   }
 
%>
</ BODY >
</ HTML >


 

posted on 2006-04-25 18:13 温柔一刀 阅读(117) 评论(0)  编辑  收藏 所属分类: java相关

只有注册用户登录后才能发表评论。


网站导航:
 
联系偶 zhupanjava@gmail.com 温柔一刀