插值,代码如下: 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();
为什么要强制转换?难道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;
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();
为什么要强制转换?难道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;
BLOB content_blob = ((OracleResultSet) rs).getBLOB("content");谢谢楼上!
问题虽然解决,但是道理仍然不明白!求各位解疑!