一段代码,仅是写入数据库的一段简单代码,其中有blob字段,分别在两台机器上测试,一台上就没有问题,另一台上报:javax.servlet.ServletException: oracle.jdbc.driver.ScrollableResultSet.getBlob(Ljava/lang/String;)Ljava/sql/Blob;  检查DB后发现,BLOB数据没有插进去,请教一下这是什么错误?怎样解决?谢谢

解决方案 »

  1.   

    插值,代码如下:
    m_JDBCConInfo.setAutoCommitFalse(); 
    String sql_blob = "SELECT CONTENT FROM table WHERE id = " + id + 
    " FOR UPDATE"; 
    ResultSet lobDetails = m_JDBCConInfo.createState().executeQuery(sql_blob); 
    if (lobDetails.next()) { 
    oracle.sql.BLOB content_blob = (oracle.sql.BLOB) lobDetails.getBlob( 
    "content"); 
    //向BLOB对象中写入数据 
    OutputStream contentOutputStream = content_blob.getBinaryOutputStream(); 
    byte[] buffer = fileNameInfo.getBytes(); 
    contentOutputStream.write(buffer); 
    contentOutputStream.flush(); 
    contentOutputStream.close(); m_JDBCConInfo.commit(); 

    lobDetails.close(); 
    m_JDBCConInfo.setAutoCommitTrue();
      

  2.   


    为什么要强制转换?难道java.sql.ResultSet的功能你觉得还不够拉风?/**
         * Retrieves the value of the designated column in the current row
         * of this <code>ResultSet</code> object as a <code>Blob</code> object
         * in the Java programming language.
         *
         * @param colName the name of the column from which to retrieve the value
         * @return a <code>Blob</code> object representing the SQL <code>BLOB</code> 
         *         value in the specified column
         * @exception SQLException if a database access error occurs
         * @since 1.2
         */
        Blob getBlob(String colName) throws SQLException;
    /**
         * Retrieves a stream that can be used to write to the <code>BLOB</code> 
         * value that this <code>Blob</code> object represents.  The stream begins
         * at position <code>pos</code>.
         *
         * @param pos the position in the <code>BLOB</code> value at which
         *        to start writing
         * @return a <code>java.io.OutputStream</code> object to which data can 
         *         be written
         * @exception SQLException if there is an error accessing the
         *            <code>BLOB</code> value
         * @see #getBinaryStream
         * @since 1.4
         */
        java.io.OutputStream setBinaryStream(long pos) throws SQLException;
      

  3.   

    问题果然出在这里,修改如下后两台机器都可正常运行:
    BLOB content_blob = ((OracleResultSet) rs).getBLOB("content");谢谢楼上!
    问题虽然解决,但是道理仍然不明白!求各位解疑!