用"select ... for update"试试

解决方案 »

  1.   

    http://dev.csdn.net/Develop/article/16/16522.shtmhttp://www.4y.com.cn/modules/newbb/viewtopic.php?viewmode=flat&topic_id=772&forum=3
    建议你看看上面的两篇文章,尤其是第一篇,你的问题在于更新的时候没有找到相应的记录!
      

  2.   

    ORA-22920: 未锁定含有LOB 值的行
    原因:包含LOB值的行在修改LOB值之前必须被锁定
    解决:在修改LOB值之前先锁定包含LOB值的行于是就有:
    yujiabian(流氓兔子雨)
      用"select ... for update"试试
      

  3.   

    select test_blob,test_clob,test_nclob  from test_lob where test_id=? for update"
    系统提示“读取违反顺序”。看来还得加紧学习啊!
      

  4.   

    我看过了 yujiabian(流氓兔子雨)提供的连接内容,但是那里提到rs一定要用Oracle提供的,难道没有别的办法吗?我给出的代码只是为了测试,实际上在应用中,数据库的连接是由专门的类的,我不想在一个系统中用两个数据库连接。大家讨论一下这个问题啊!
      

  5.   

    代码的问题,注意下面Action的第二条:ORA-01002: fetch out of sequence 
    Cause: This error means that a fetch has been attempted from a cursor which is no longer valid. Note that a PL/SQL cursor loop implicitly does fetches, and thus may also cause this error. There are a number of possible causes for this error, including: 
        1) Fetching from a cursor after the last row has been retrieved and the ORA-1403 error returned. 
        2) If the cursor has been opened with the FOR UPDATE clause, fetching after a COMMIT has been issued will return the error. 
        3) Rebinding any placeholders in the SQL statement, then issuing a fetch before reexecuting the statement.
    Action: 
        1) Do not issue a fetch statement after the last row has been retrieved - there are no more rows to fetch. 
        2) Do not issue a COMMIT inside a fetch loop for a cursor that has been opened FOR UPDATE. 
        3) Reexecute the statement after rebinding, then attempt to fetch again.
      

  6.   

    http://blog.csdn.net/kenly_zhang/archive/2005/01/26/268868.aspx
      

  7.   

    setAutoCommit(false)取消自动提交
      

  8.   

    谢谢各位用上面的方法blob存储和读取都没有问题了,但是clob该怎么处理呢, 我用一下语句
                    OutputStream outstream=t_cb.getAsciiOutputStream();
                    outstream.write(cmFileBody,0, cSize);
                    outstream.close();
    能够存储进去,但是读取的时候,全成了空格,我用字符转换转换了之后就全成了问号!代码如下:<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
    <%@ page import="java.io.*" %>
    <%@ page import="oracle.sql.BLOB" %>
    <%@ page import="oracle.sql.CLOB" %><HTML>
    <HEAD>
    <TITLE>大对象测试</TITLE></HEAD>
    <body>
    <%
         Connection conn;
         Statement stmt;
         //oracle.jdbc.OracleResultSet rs;
         ResultSet rs;
         String DBDriver;
         String UserName;
         String PassWord;
         String DBUrl;
         String blobstr;
         String clobstr;
    DBDriver = "oracle.jdbc.driver.OracleDriver";
            UserName = "test";
            PassWord = "test";
            DBUrl = "jdbc:oracle:thin:@localhost:1521:test";
            Class.forName(DBDriver);
            conn = DriverManager.getConnection(DBUrl, UserName, PassWord);
            stmt = conn.createStatement();
            String test_title=request.getParameter("test_title");
            //out.println(test_title);
    String test_blob=request.getParameter("test_blob");
    //out.println("***"+test_blob);
    String test_clob=request.getParameter("test_clob");
    String test_nclob=request.getParameter("test_nclob");
            String sqlStr="insert into  test_lob(test_id,test_title,test_blob,test_clob) values(test_id.nextval,'"+test_title+"',EMPTY_BLOB(),EMPTY_CLOB())";
    //out.println(sqlStr);
            stmt.executeUpdate(sqlStr); 
    CLOB t_cb;
    BLOB t_bb;
    CLOB t_ncb;
    conn.setAutoCommit(false);
    sqlStr="select test_blob,test_clob,test_nclob  from test_lob where test_id=7 for update";
    rs=stmt.executeQuery(sqlStr);
    if(rs.next()){
    t_bb=((oracle.jdbc.OracleResultSet)rs).getBLOB("test_blob");
    t_cb=((oracle.jdbc.OracleResultSet)rs).getCLOB("test_clob");
    byte[] mFileBody;
    byte[] cmFileBody;
    byte[] imFileBody;
    byte[] icmFileBody;
    int vSize;
    int cSize;
    vSize=(int)t_bb.length();
    cSize=(int)t_cb.length();
    imFileBody = new byte[vSize];
    icmFileBody = new byte[cSize];
             InputStream instream=t_bb.getBinaryStream();
             InputStream cinstream=t_cb.getAsciiStream();
            
             instream.read(imFileBody,0,vSize);
             cinstream.read(icmFileBody,0,cSize);
             instream.close();
             cinstream.close();
             blobstr=new String(imFileBody);
    clobstr=new String(icmFileBody);
    clobstr=new String(clobstr.getBytes("ISO-8859-1"));
    out.println(blobstr);
    out.println("<br>==============================================");
             out.println(clobstr);
        if(t_bb!=null){ 
            mFileBody=test_blob.getBytes("ISO8859-1");
            cmFileBody=test_clob.getBytes("ISO8859-1");
            
                     vSize=mFileBody.length;
                     cSize=mFileBody.length;
            //out.println("***"+vSize);
            OutputStream outstream=t_bb.getBinaryOutputStream();
            OutputStream coutstream=t_cb.getAsciiOutputStream();
            Writer is2 = new StringWriter(test_clob);
                    outstream.write(mFileBody,0, vSize);
                    coutstream.write(cmFileBody,0, cSize);
                    outstream.close();
                    coutstream.close();
         }
    }
    conn.commit();
             conn.setAutoCommit(true);
         %>
     </BODY>
    </HTML>
      

  9.   

    问题解决了!本人对于lob的操作有了初步的认识,谢谢各位帮助!