java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]ResultSet can not re-read row data for column 3.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseResultSet.validateColumnIndex(Unknown Source)
at com.microsoft.jdbc.base.BaseResultSet.getString(Unknown Source)
at com.jc.db.HugDAO.setBean(HugDAO.java:525)
at com.jc.db.HugDAO.execPrcPageSelect(HugDAO.java:775)
at com.jc.util.tag.Pagination.getReslList(Pagination.java:142)
at com.jc.util.tag.Pagination.doEndTag(Pagination.java:190)
at org.apache.jsp.back.selectProductioncase_jsp._jspService(selectProductioncase_jsp.java:164)
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 com.jc.filter.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:122)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
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)
是因为:
com.microsoft.jdbc.sqlserver.SQLServerDriver。存在不足
为了解决这个错误,跟踪程序忙了大半天,也没有查出问题所在。只能确定在在rs.getString("XXX")的时候必然会出现错误(rs为ResultSet对象)。那么现在就模拟以下当时的
环境:
数据库表:TestTable
表字段及类型:
guid char(38)
title varchar(100)
content Text
username varchar(20)
查询sql语句:
select guid,username,content,title from TestTable
java代码:
rs.getString("guid");
rs.getBinaryStream("content");
rs.getString("username");
-----------------------------------------------------------
上面那段代码,很不荣幸是。使用微软的驱动,必然会报错(就是上面说的那个错误)。如果你跟踪的话,必然是这一行:rs.getString("username")抛出错误。
那么,如果你把rs.getString("username")和rs.getBinaryStream("content");位置互换以下,会怎么样呢。结果就是可以正常运行。
为什么会出现这种情况呢,因为微软的驱动,在包含了blob或clob类型(就是Image和Text类型)的字段。那么就必须按照select顺序查询,且不支持重复查询
解决方案要么按照顺序去读,要么就该换驱动。
我换了驱动:
Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
String URL = "jdbc:jtds:sqlserver://127.0.0.1:1433/student";
导入jtds-1.2.2.jar 就可以了;