Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> OracleThinBlob ClassCast Exception
Hi,
We are using weblogic8.1 jdk1.4.2 And oracle 8i.
We are trying to set the value for Blob column using the following
code snippet :-
The error we are seeing on this line "java.io.OutputStream os =
((OracleThinBlob)blob).getBinaryOutputStream();
" is:-
java.lang.ClassCastException
at com.aetrion.lucene.store.DBDirectory.setBLOB
Connection conn = null; ResultSet rs = null; try{ byte[] data = os.toByteArray(); System.out.println("Length of the data is" + data.length); conn = DriverManager.getConnection( db.url, db.username, db.password); PreparedStatement ps = conn.prepareStatement( "update " + tableName + " set name = ?, lastmodified = ?, length = ?, data = empty_blob() where name = ? and directory_name = ?"); ps.setString(1, name); ps.setString(2, String.valueOf(System.currentTimeMillis())); ps.setLong(3, (long)data.length); // ps.setBytes(4, data); ps.setString(4, name); ps.setString(5, directoryName); int rowCount = ps.executeUpdate(); if(rowCount != 1){ error("No data saved"); } conn.setAutoCommit(false); String selectStmt = "select data from lucene_indeces where name = ? and directory_name = ? for update"; PreparedStatement pstmt = conn.prepareStatement( selectStmt ); pstmt.setString( 1, name ); pstmt.setString( 2, directoryName ); rs = pstmt.executeQuery(); rs.next(); //if (!rs.next() ) ERRLR_CONDITION setBLOB( rs, 1, data ); conn.setAutoCommit(true); } catch(SQLException e){ error("SQL error saving data", e); } catch(IOException e){ error("IO error saving data", e); } catch(Exception e){ error("error saving data", e); } finally { close(conn); }
public void setBLOB (ResultSet rs, int inIndex, byte [] inBytes)
throws Exception
{
//oracle.sql.BLOB blob = (oracle.sql.BLOB)rs .getObject( inIndex
);
//java.io.OutputStream os = blob.getBinaryOutputStream();
java.sql.Blob blob = rs.getBlob("DATA"); java.io.OutputStream os =
os.write(inBytes); os.flush(); os.close();