huhetala
2010-05-11 20:44
浏览 294
已采纳

新手请教:JSP访问数据库

数据查询成功,但是输不出来内容,报异常

<%@ page language="java" contentType="text/html; charset=gb2312" pageEncoding="gb2312" errorPage=""%>



基本信息查询

学号


[b]showStuInfo.jsp[/b]
<%@ page language="java" contentType="text/html; charset=gb2312" pageEncoding="gb2312"%>
<%@ page import="java.sql.*" %>
/jsp:useBean
<%
String number = request.getParameter("number");
String query_sql = "select * from db_Student where Sno = '"+number+"';";

ResultSet rs = queryStu.excuteQuery(query_sql);
//String stu[] = new String[6];

System.out.println(rs.getString(1));

// System.out.println(stu[2]);
// System.out.println(stu[3]);
%>

报的异常是:

select * from db_Student where Sno = '0304060206';
查询成功!---------这两句是在查询数据库的Java文件里面输出来的

就是以下异常就不知道咋回事儿了
2010-5-11 20:23:13 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet jsp threw exception
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid operation for the current cursor position.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseResultSet.validateCursorPosition(Unknown Source)
at com.microsoft.jdbc.base.BaseResultSet.getString(Unknown Source)
at org.apache.jsp.showStuInfo_jsp._jspService(showStuInfo_jsp.java:76)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

5条回答 默认 最新

  • 拽拽的初行者 2010-05-11 20:59
    最佳回答

    [b]打错了 ,是 “遍历结果集”[/b]
    [code="java"]while(rs.next()){
    rs.getXXX(1);
    rs.getXXX(2);
    // .....
    }[/code]

    评论
    解决 无用
    打赏 举报
查看更多回答(4条)

相关推荐 更多相似问题