概述
我用的tomcat 7.0,eclipse 8.5,已经把class12.jar放到tomcat的lib目录下,oracle是9.2,表login的列we和ss都是varchar2(10)类型。在执行下列代码时:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:bksfhcxt";
String user="system";
String password="oracle2";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt = conn.createStatement();
String sql="select * from LOGIN";
ResultSet rs=stmt.executeQuery(sql);
if (rs !=null){out.println("rs.getString(3)");}
rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
页面能正确显示 rs.getString(3) 字符出来,
但在执行下面语句时:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:bksfhcxt";
String user="system";
String password="oracle2";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt = conn.createStatement();
String sql="select * from LOGIN";
ResultSet rs=stmt.executeQuery(sql);
//if (rs !=null){out.println("rs.getString(3)");}
while(rs.next()){%>
<%=rs.getString(1)%>
<%=rs.getString(2)%>
<%}%>
<table>
<tr>
<td>员工号</td>
<td>姓名</td>
</tr>
<tr>
<td><%=rs.getString(1)%></td>
<td><%=rs.getString(2)%></td>
</tr>
</table>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
则报以下错误:
type Exception report
message An exception occurred processing JSP page /index.jsp at line 24
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 24
21: <td>濮撳悕</td>
22: </tr>
23: <tr>
24: <td><%=rs.getString(1)%></td>
25: <td><%=rs.getString(2)%></td>
26:
27: </tr>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
javax.servlet.ServletException: java.sql.SQLException: [Microsoft][ODBC 驱动程序管理器] 无效的游标状态
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:912)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:841)
org.apache.jsp.index_jsp._jspService(index_jsp.java:116)
原因比较简单,我之前的代码是:
while(rs.next()){%>
<%=rs.getString(1)%>
<%=rs.getString(2)%>
<%}%>
while循环这里必然已经把数据集遍历完毕了,也就是游标走到了最后一行的后面(EOF行)。
然后我又想:
<td><%=rs.getString(1)%></td>
<td><%=rs.getString(2)%></td>
必然错误。
应该是把逻辑搞错了,应该是:
String sql="select * from LOGIN";
ResultSet rs=stmt.executeQuery(sql);
%>
<table>
<tr>
<td>员工号</td>
<td>姓名</td>
</tr>
<% while(rs.next()){ %>
<tr>
<td><%=rs.getString(1)%></td>
<td><%=rs.getString(2)%></td>
</tr>
<% } %>
</table>
<%
rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
此文由Web开发之答疑解惑源整理,若需转载 ,请注明原文(ODBC驱动程序管理器无效的游标状态)出处:http://www.znjcx.com/html/y2012/3310_odbc-driver-manager-invalid-cursor-state.html
最后
以上就是神勇方盒为你收集整理的ODBC驱动程序管理器无效的游标状态的全部内容,希望文章能够帮你解决ODBC驱动程序管理器无效的游标状态所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复