当前位置: 代码迷 >> Java相关 >> 请大家给解决个问题!谢谢先
  详细解决方案

请大家给解决个问题!谢谢先

热度:167   发布时间:2008-08-18 18:27:13.0
请大家给解决个问题!谢谢先
开发BBS系统,用的环境是lomoz ecplise3.2 ,sqlserver2000 dep ,在运行下面这个页面的时候,TOMCAT SERVER提示:
root cause

[bo]javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC]ResultSet can not re-read row data for column 1.[/bo]

编码如下:

<%@ page language="java" contentType="text/html; charset=gbk"
    pageEncoding="gbk"%>
<%@ page import="java.sql.*" %>

<%!
String str = "";

private void tree(Connection conn, int id, int level) {
    Statement stmt = null;
    ResultSet rs = null;
    String preStr = "";
    for(int i=0; i<level; i++) {
        preStr += "----";
    }
    try {
        stmt = conn.createStatement();
        String sql = "select * from article where pid = " + id;
        rs = stmt.executeQuery(sql);
        String strLogin = "";
        
        while(rs.next()) {
            
            str += "<tr><td>" + rs.getInt("id") + "</td><td>" +
                   preStr + "<a href='ShowArticleDetail.jsp?id=" + rs.getInt("id") + "'>" +
                   rs.getString("title") + "</a></td>" +
                   strLogin +
                   "</td></tr>";
            if(rs.getInt("isleaf") != 0) {
                tree(conn, rs.getInt("id"), level+1);
            }
        }
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        try {
            if(rs != null) {
                rs.close();
                rs = null;
            }
            if(stmt != null) {
                stmt.close();
                stmt = null;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
%>

<%
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String url1 ="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=bbs";
String url2 ="sa";
String url3 ="sa";
Connection conn =DriverManager.getConnection(url1,url2,url3);


Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from article where pid = 0");
String strLogin = "";
while(rs.next()) {
    
    str += "<tr><td>" + rs.getInt("id") + "</td><td>" +
           "<a href='ShowArticleDetail.jsp?id=" + rs.getInt("id") + "'>" +
           rs.getString("title") + "</a></td>" +
           strLogin +
           "</td></tr>";
       if(rs.getInt("isleaf") != 0) {
           tree(conn, rs.getInt("id"), 1);
       }
}
rs.close();
stmt.close();
conn.close();
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>Insert title here</title>
</head>
<body>
<a href="Post.jsp">发表新帖</a>
<table border="1">
<%= str %>
<%
str = "";

%>
</table>
</body>

</html>
搜索更多相关的解决方案: 有问题啊!  

----------------解决方案--------------------------------------------------------
根据错误提示找贝。
ResultSet can not re-read row data for column 1.
找不到原因就google.

是ms的驱动问题。。。。
网上一堆,搜了就看见了。。。。
----------------解决方案--------------------------------------------------------
re:
数据源是否配置正确
建议在写代码的时候多增加些捕获异常的代码
这样能查出原因
----------------解决方案--------------------------------------------------------
  相关解决方案