请大侠高手们帮小弟一把,谢谢!

zenki6231 2006-03-16 01:49:36
这是我在线考试系统的代码:
<%@ page contentType="text/html; charset=gb2312" language="java" errorPage="" %>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<jsp:useBean id="data" scope="page" class="teachingsite.examination" />
<jsp:useBean id="str" scope="page" class="teachingsite.str_filter"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>在线考试系统</title>
</head>
<%String submit=request.getParameter("submit");
if(submit!=null){
String sql,hidden="",radio="",check="",check_t="",check_r="",answer;
ResultSet rs;
int token_count,type,score=0;
for(int i=0;i<10;i++){
hidden="h"+i;
hidden=request.getParameter(hidden);
sql="select * from examination where id ="+hidden;
rs=data.executeQuery(sql);
type=rs.getInt(4);
answer=rs.getString("answer");
if(type==0){
radio="r"+i;
radio=request.getParameter(radio)+"/";
if(radio.equals(answer)){
score+=rs.getInt("score");
}
}
else{
for(int j=0;j<4;j++){
check_t="c"+i+j;
check_r=request.getParameter(check_t);
if(check_r!=null)
check+=check_r+"/";
}
if(check.equals(answer)){
score+=rs.getInt("score");
}
check="";
}
}%>
<body bgcolor="#00CCFF" text="#000000">
<center>您的成绩是<%=score%>分
<a href="examination.jsp">继续考试</a>
</center>
</body>
</html>
<%}else{
%>

<body bgcolor="#00CCFF" text="#000000">
<center>
<h1>在线考试系统</h1>
<form action="examination.jsp" method="post">
<% Vector v1=new Vector();
Random r1=new Random();
int count=0;
Double check,i1;
boolean haved=false;
while(count<10){
i1=new Double(Math.abs(Math.round(r1.nextGaussian()*100)));
//v1.addElement(i1);
//count++;
if(v1==null) v1.addElement(i1);
for(int i=0;i<v1.size();i++){
check=(Double)v1.elementAt(i);
if(check.intValue()==i1.intValue()) haved=true;
if(check.intValue()==0) haved=true;
}
if(!haved){
v1.addElement(i1);
count++;
}
}
Double id;
String sql;%>
<% for(int i=0;i<v1.size();i++){
id=(Double)v1.elementAt(i);
sql="select * from examination where id="+id.intValue();
ResultSet rs=data.executeQuery(sql);
rs.next();%>
<font size="+2"><b>第<%=i+1%>题:<%=str.strtochn(rs.getString("title"))%></b></font>
<br>分数:
<%int score=rs.getInt(6);
out.print(score);%>
<br>
<% int type =rs.getInt(4);
StringTokenizer content=new StringTokenizer(rs.getString(3),"/");
int token_count=content.countTokens();%>
<ul>
<% if(type==0){
for(int j=0;j<token_count;j++){
%>
<li><input type="radio" name="r<%=i%>" value="<%=j%>">
<%=str.strtochn((String)content.nextElement())%>
</li>
<%}
}else{
for(int j=0;j<token_count;j++){
%>
<li><input type="checkbox" name="c<%=i%><%=j%>" value="<%=j%>">
<%=str.strtochn((String)content.nextElement())%>
</li>
<%}
}%>
</ul><p>
<input type="hidden" name="h<%=i%>" value="<%=rs.getInt(1)%>">
<%
rs.close();
}
%>
<input type="submit" name="submit" value="交 卷">
}
</form>
</center>
</body>
</html>
<%}%>
examination.java代码如下:
package teachingsite;
import java.sql.*;
public class examination{
String sDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr="jdbc:odbc:teachingsitedb";
Connection conn=null;
ResultSet rs=null;
Statement stmt;

public examination(){
try{
Class.forName(sDBDriver);
conn=DriverManager.getConnection(sConnStr);
stmt=conn.createStatement();
}
catch(java.lang.ClassNotFoundException e){
System.err.print("create():"+e.getMessage());
}
catch(SQLException e){
}
}
public boolean executeUpdate(String sql){
try{
stmt.executeUpdate(sql);
return true;
}catch(SQLException e){
System.err.println("aq.executeUpdate:"+e.getMessage());
}
return false;
}
public ResultSet executeQuery(String sql)
{
rs=null;
try{
rs=stmt.executeQuery(sql);
}
catch(SQLException ex){
System.err.println("aq.executeQuery:"+ex.getMessage());
}
return rs;
}
public Statement stmt(){
return stmt;
}
public void close(){
try{
rs.close();
stmt.close();
conn.close();
}catch(Exception e){
System.out.println(e.toString());
}
}
}
str_filter.java代码如下;
package teachingsite;

public class str_filter{

public str_filter(){
}
public String strtochn(String str_in){
byte[] byte1=str_in.getBytes();
String temp="";
try{
temp=new String(byte1,"8859_1");
}
catch(Exception e){
}

return temp;
}
}
报错信息如下:
description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: [Microsoft][ODBC 驱动程序管理器] 无效的游标状态
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
org.apache.jsp.teachingsite.examination_jsp._jspService(org.apache.jsp.teachingsite.examination_jsp:228)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

java.sql.SQLException: [Microsoft][ODBC 驱动程序管理器] 无效的游标状态
sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
sun.jdbc.odbc.JdbcOdbc.SQLGetDataString(JdbcOdbc.java:3908)
sun.jdbc.odbc.JdbcOdbcResultSet.getDataString(JdbcOdbcResultSet.java:5699)
sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.java:353)
sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.java:410)
org.apache.jsp.teachingsite.examination_jsp._jspService(org.apache.jsp.teachingsite.examination_jsp:156)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

...全文
45 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
zenki6231 2006-03-17
大侠,好像还是不行啊,依然报错:无效的游标状态:(
回复
interpb 2006-03-16
rs=data.executeQuery(sql);
rs.next();//加上这句,让游标下移,每读一条移一次
type=rs.getInt(4);
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2006-03-16 01:49
社区公告
暂无公告