请帮忙看一看这段代码那错了(50分)

  • 主题发起人 丛艳全
  • 开始时间

丛艳全

Unregistered / Unconfirmed
GUEST, unregistred user!
<%@ page contentType=&quot;text/html;
charset=gb2312&quot;
language=&quot;java&quot;
import=&quot;java.sql.*&quot;
errorPage=&quot;&quot;
%>
<%@ page import=&quot;java.sql.*&quot;%>
<html>
<head>
<meta http-equiv=&quot;Content-Type&quot;
content=&quot;text/html;
charset=gb2312&quot;>
<META HTTP-EQUIV=&quot;refresh&quot;
CONTENT=&quot;10&quot;/>
<title>无标题文档</title>
</head>
<body>
<%
Connection con;
ResultSet rs;
Statement stmt;
String sql;
Class.forName(&quot;sun.jdbc.odbc.JdbcOdbcDriver&quot;);
con=DriverManager.getConnection(&quot;jdbc:eek:dbc:login&quot;,&quot;sa&quot;,&quot;sa&quot;);
stmt=con.createStatement();
sql=&quot;select * from edu&quot;;
rs=stmt.executeQuery(sql);
%>
<table border=&quot;1&quot;
width=&quot;100%&quot;>
<tr>
<td width=&quot;50%&quot;><%=rs.getString(&quot;ID&quot;)%></td>
<td width=&quot;50%&quot;><%=rs.getString(&quot;Education&quot;)%></td>
</tr>
</table>
</body>
</html>
提示错误信息为:无效游标
 
B

bytelife

Unregistered / Unconfirmed
GUEST, unregistred user!
rs没有定义
 

丛艳全

Unregistered / Unconfirmed
GUEST, unregistred user!
RS就算是定义了,也是出这种错误啊
 
L

lbxwing

Unregistered / Unconfirmed
GUEST, unregistred user!
这样...
<table border=&quot;1&quot;
width=&quot;100%&quot;>
<%while(rs.next()){%>
<tr>
<td width=&quot;50%&quot;><%=rs.getString(&quot;ID&quot;)%></td>
<td width=&quot;50%&quot;><%=rs.getString(&quot;Education&quot;)%></td>
</tr>
<%}%>
</table>
 
Y

yangxiao_jiang

Unregistered / Unconfirmed
GUEST, unregistred user!
同意 lbxwing
必须用
<%while(rs.next()){%>
然后才能取值
 
H

happycyp

Unregistered / Unconfirmed
GUEST, unregistred user!
同意楼上的。JAVA操作数据库,打开后,默认指向第一条记录的前面,而不是第一条。
所以要先
rs.next()
才能访问第一条数据.
 

丛艳全

Unregistered / Unconfirmed
GUEST, unregistred user!
多人接受答案了。
 
顶部