Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> OracleThinBlob ClassCast Exception

OracleThinBlob ClassCast Exception

From: Nikhil <g_nick_2000_at_yahoo.com>
Date: 27 Apr 2004 17:44:01 -0700
Message-ID: <cdf89255.0404271644.42e0d2e0@posting.google.com>


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



private void closeStream(String name, DBOutputStream os) {
        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 =

((OracleThinBlob)blob).getBinaryOutputStream();
    os.write(inBytes);
    os.flush();
    os.close();

  } Received on Tue Apr 27 2004 - 19:44:01 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US