| sqlBuffer.append(keyValue);
//注意这里的”for update”
sqlBuffer.append("'''' for update ");
stmt = conn.createStatement();
rs = (OracleResultSet) stmt.executeQuery(sqlBuffer.toString());
if (!rs.next())
{
rs.close();
stmt.close();
throw new IllegalArgumentException(
"no record found for keyValue: ''''" + keyValue + "''''");
}
blob = rs.getBLOB(1);
OutputStream outstream = blob.getBinaryOutputStream();
int bufferSize = blob.getChunkSize();
byte[] buffer = new byte[bufferSize];
int bytesRead = -1;
while ((bytesRead = instream.read(buffer)) != -1)
{
outstream.write(buffer, 0, bytesRead);
}
instream.close();
outstream.close();
rs.close();
stmt.close();
}
catch (SQLException e)
{
throw e;
}
catch (IOException e)
{
throw e;
}
finally {
conn.setAutoCommit(oldAutoCommit);
}
}
二、PL/SQL下
(例子表结构如一所示)
i.插入一空的Blob。
…
declare
bufferBlob BLOB;
data RAW(…)
…
INSERT INTO Student VALUES(‘zhangsan’, 20 , empty_blob() );
…
ii.更新该纪录的Blob。
…
SELECT Picture INTO bufferBlob FROM Student WHERE Name=’zhangsan’ FOR UPDATE;
DBMS_LOB.OPEN(bufferBlob , dbms_lob.lob_readwrite);
dbms_lob.write(bufferBlob , utl_raw.length(data) , data);
…
(待续)
上一页 [1] [2] |