java.io.IOException: [BEA][SQLServer JDBC Driver]Object has been closed.

环境:weblogic10.0,sqlserver2000,打了sp4的补丁
java.io.IOException: [BEA][SQLServer JDBC Driver]Object has been closed.
        at weblogic.jdbc.base.BaseInputStreamWrapper.validateClosedState(Unknown Source)
        at weblogic.jdbc.base.BaseInputStreamWrapper.read(Unknown Source)

目标:读取一条记录,某个字段为image,读取后,直接放入到byte[]中。
源码:
<%@ page language="java" pageEncoding="GBK"%>
<%@page import="java.io.InputStream"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.io.*"%>
<%@page import="java.sql.*"%>
<%
    InputStream fr = null;
   
    try
    {
        Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver")
                .newInstance();
        String url = "jdbc:microsoft:sqlserver://10.4.1.90:1433;DatabaseName=QK", user = "qxs", password = "2400";
        Connection conn = DriverManager.getConnection(url, user,
                password);
        Statement stmt = conn.createStatement();
        ResultSet rs;
        String strSql = "select * from Qb_Mm5_Data where id='8' and  dt='2009-07-07 20:00:00'";
        rs = stmt.executeQuery(strSql);
       
        if (rs != null)
        {
            while (rs.next())
            {
                fr = rs.getBinaryStream("fdata");
            }
        }
       
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        int b = 0;
        while ((b = fr.read()) != -1)
            baos.write(b);
       
        for (int i = 0; i < baos.toByteArray().length; i++)
        {
            out.println("---" + baos.toByteArray()[i]);
        }
       
        try
        {
            if (fr != null)
            {
                fr.close();
                fr = null;
            }
            rs.close();
            stmt.close();
            conn.close();
           
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
       
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
%>
报错位置为: while ((b = fr.read()) != -1)处

你可能感兴趣的:(java,sql,jdbc,weblogic,Microsoft)