代码的问题,注意下面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.
建议你看看上面的两篇文章,尤其是第一篇,你的问题在于更新的时候没有找到相应的记录!
原因:包含LOB值的行在修改LOB值之前必须被锁定
解决:在修改LOB值之前先锁定包含LOB值的行于是就有:
yujiabian(流氓兔子雨)
用"select ... for update"试试
系统提示“读取违反顺序”。看来还得加紧学习啊!
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.
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>