<%@ page contentType="text/html; charset=big5" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<title>无标题文档</title>
</head><body>
<%
  String name,number;
  int maths,physics,english;
  Connection conn;
  Statement sql;
  ResultSet rs;
  try
  {
  Class.forName("oracle,jdbc,driver.OracleDriver").newInstance();
  }
  catch(ClassNotFoundException e){}
  try{
  String url="jdbc:odbc:thin:@localhost:1521:JPS";
  String user="JSPDEV";
  String password="100200";
  conn=DriverManager.getConnection(url,user,password);
  sql=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
  //返回可流動的結果集。
  rs=sql.executeQuery("SELECT * FROM STUDENT");
  //將返回到最后一行
  rs.last();
  //獲取最后一行的行號
  int lownumber=rs.getRow();
  out.println("該表共有"+lownumber+"條記錄");
  out.println("<br>現有逆序輸出記錄﹕");
  out.println("<table border>");
  out.println("<tr>");
  out.println("<th width=100>"+"學號");
  out.println("<th width=100>"+"姓名");
  out.println("<th width=100>"+"數學成績");
  out.println("<th width=100>"+"英語成績");
  out.println("<th width=100>"+"物理成績");
  out.println("</tr>");
  
  //為了逆序輸出記錄﹐需將游標移動到最后一行
  rs.afterLast();
  while(rs.previous())
  {out.println("<tr>");
  number=rs.getString(1);
  out.println("<td>"+number+"</td>");
  name=rs.getString(2);
  out.println("<td>"+name+"</td>");
  maths=rs.getInt("maths");
  out.println("<td>"+maths+"</td>");
  english=rs.getInt("english");
  out.println("<td>"+english+"</td>");
  physics=rs.getInt("physics");
  out.println("<td>"+physics+"</td>");
  out.println("</tr>");
  
  }
  out.println("</table>");
  out.println("單獨輸出第5條記錄<br>");
  rs.absolute(5);
    number=rs.getString(1);
out.println(number+", ");
name=rs.getString(2);
out.println(name+", ");
maths=rs.getInt("maths");
out.println(maths+", ");
english=rs.getInt("english");
out.println(english+", ");
physics=rs.getInt("physics");
out.println(physics+". ");
conn.close();
  }
  catch(SQLException e1){}
%>
</body>
</html>

解决方案 »

  1.   

    rs=sql.executeQuery("SELECT * FROM STUDENT");后就用
    int i;
    while(rs.next()){
    i++
    number=rs.getString(1);
    ...
    ...
    }
    不用用rs.last,要取number,定义int i;
      

  2.   

    http://www.itgene.cn/itgene/article/articleView.asp?ID=512
    看看这篇文章吧,了解一下ResultSet
      

  3.   

    還是不對哦。我去掉了那個RS.LAST()的在關代碼都還是空白頁整個頁面都是空白的
      

  4.   

    <%@ page contentType="text/html; charset=big5" language="java" import="java.sql.*" errorPage="" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=big5">
    <title>无标题文档</title>
    </head><body>
    <%
    String name,number;
    int maths,physics,english;
    Connection conn;
    Statement sql;
    ResultSet rs;
    try
    {
    Class.forName("oracle,jdbc,driver.OracleDriver").newInstance();
    }
    catch(ClassNotFoundException e){}
    try{
    String url="jdbc:odbc:thin:@localhost:1521:JPS";
    String user="JSPDEV";
    String password="100200";
    conn=DriverManager.getConnection(url,user,password);
    sql=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
    //返回可流動的結果集。
    rs=sql.executeQuery("SELECT * FROM STUDENT");
    out.println("<table border>");
    out.println("<tr>");
    out.println("<th width=100>"+"學號");
    out.println("<th width=100>"+"姓名");
    out.println("<th width=100>"+"數學成績");
    out.println("<th width=100>"+"英語成績");
    out.println("<th width=100>"+"物理成績");
    out.println("</tr>");int i=0;
    while(rs.previous())
    {
    i++;
    out.println("<tr>");
    number=rs.getString(1);
    out.println("<td>"+number+"</td>");
    name=rs.getString(2);
    out.println("<td>"+name+"</td>");
    maths=rs.getInt("maths");
    out.println("<td>"+maths+"</td>");
    english=rs.getInt("english");
    out.println("<td>"+english+"</td>");
    physics=rs.getInt("physics");
    out.println("<td>"+physics+"</td>");
    out.println("</tr>");}
    //////////////////////////////////////////////////////
    //注意:在while(rs.next()){}外部不要在调用rs.get....
    ////////////////////////////////////////////////////
    out.println("</table>");
    out.println("共有记录"+i+"条");
    out.println("單獨輸出第5條記錄<br>");
    conn.close();
    }
    catch(SQLException e1){}
    %>
    </body>
    </html>你试试把,我觉得你最主要是把rs的数据显示出来,完了以后你在试试其他功能。
      

  5.   

    不好意思:while(rs.previous())这句改为while(rs.next())
      

  6.   

    我把最后面的那個catch(SQLException e1){}改為catch(SQLException e1){out.println(e1.toString());}出現這樣的錯誤。java.sql.SQLException: [Microsoft][ODBC 驅動程式管理員] 找不到資料來源名稱且未指定預設的驅動程式
    才發現原來是這里出錯了String url="jdbc:odbc:thin:@localhost:1521:JPS";應該改為String url="jdbc:oracle:thin:@localhost:1521:JPS";改好之后還是有錯誤java.sql.SQLException: No suitable driver 但是我明明有把oracle 的驅動放到LIB文件夾里面了啊
      

  7.   

    rlqiang(不留)我用你的代碼運行還是老樣子。
      

  8.   

    唉﹐都是筆誤惹的禍﹐還在這里
    try
    {
    Class.forName("oracle,jdbc,driver.OracleDriver").newInstance();
    }oracle,jdbc,driver.OracleDriver這里應該是英文的句話不是逗號﹐改為
    try
    {
    Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
    }
    就可以了。謝謝不留老哥了。