6 Replies Latest reply on Feb 28, 2002 6:36 PM by davidjencks

    EJB-BLOB problem.

    rohit

      Hi,
      I am trying to insert a blob object in the oracle 8i database using ejb session bean .i am using the BLOB class of oracle.sql package however it throws the following exception
      java.lang.ClassCastException: org.jboss.pool.jdbc.ResultSetInPool.

      when the method is executed.

      i am using the following code.

      strQuery="SELECT APPL_REF_MATERIAL_BLOB FROM PTS_APPL_REF_MATERIAL WHERE APPL_REF_MATERIAL_ID="+strPk;
      //strPk is the primary key.
      stmt=con.createStatement();
      rs=stmt.executeQuery(strQuery);
      while(rs.next())
      {

      BLOB blob=((OracleResultSet)rs).getBLOB(1);
      //error is thrown on above line
      FileInputStream instream=new FileInputStream(appRef.getRefMaterial());//returns a file object
      OutputStream outStream=blob.getBinaryOutputStream();
      int size=blob.getBufferSize();
      byte buffer[]=new byte[size];
      int length=-1;
      while((length=instream.read(buffer))!=-1)
      {
      outStream.write(buffer,0,length);
      }
      instream.close();
      outStream.close();

      }

        • 1. Re: EJB-BLOB problem.
          amccullo

          I am fairly new at this so I may be way off but it is probably better to use the java.sql.Blob class instead of the Oracle specific BLOB object.

          Blob blob = rs.getBlob(1);

          Your class cast exception comes from the fact that the ResultSet you get back does not inherit from the Oracle version. I don't think you can use JBoss connection pooling and still use the non-standard Oracle functionality. If you need the Oracle functionality you will have to use the DriverManager.getConnection(url). Or at least that is what I have found.

          • 2. Re: EJB-BLOB problem.
            rohit

            Hello ,
            I am intending to save a blob to the table and not retrieve it.The original code saves a blob to the database.
            Blob interface which is provided by java.sql.* package doesnt have any method which returns the outputstream object.
            That is the reason why I have used BLOB of oracle.sql package.

            • 3. Re: EJB-BLOB problem.
              davidjencks

              BLOB blob=((OracleResultSet)(rs.getUnderlyingResultSet())).getBLOB(1);

              • 4. Re: EJB-BLOB problem.
                rohit

                Thanks.
                I tried this code but it throws the following compilation error.
                cannot resolve symbol
                symbol : method getUnderlyingResultSet ()
                location: interface java.sql.ResultSet
                BLOB blob=((OracleResultSet)(rs.getUnderlyingResultSet())).getBLOB(1);

                Compiler tries to find the method getUnderlyingResultSet() in java.sql.ResultSet interface which it doesnt find hence the error.

                • 5. Re: EJB-BLOB problem.
                  amccullo

                  You must cast the 'rs' object to "org.jboss.pool.jdbc.ResultSetInPool" before you can call the getUnderlyingResultSet method.

                  BLOB blob =
                  ((OracleResultSet)(((org.jboss.pool.jdbc.ResultSetInPool)rs).getUnderlyingResultSet())).getBLOB(1);

                  Let me know if that works as I have not tried it.

                  • 6. Re: EJB-BLOB problem.
                    davidjencks

                    Yes, use your imagination;-). You may also need to cast to the Oracle blob type.