当前位置: 代码迷 >> Java Web开发 >> ODBC 驱动程序管理器] 无效的游标状态 的有关问题
  详细解决方案

ODBC 驱动程序管理器] 无效的游标状态 的有关问题

热度:2422   发布时间:2013-02-25 21:10:51.0
ODBC 驱动程序管理器] 无效的游标状态 的问题
我用的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)
.................................................................

这种情况是什么原因,如何解决,还请高手们指点一下。


------解决方案--------------------------------------------------------
  相关解决方案