Oracle.sql.BLOB as array

Hi,
I have a database table(say MY_BLOB_TABLE.) having one blob column
I want to send each blob column as an attachment to a single email i.e. I for a particular case if I have 10 qualifying rows in MY_BLOB_TABLE,I want to send all these 10 blobs as different attachments with a SINGLE email.
I have the working code (from asktom) that allows me to send one attchment per email ..so I changed the code so that it takes array types to the things..
here is my code:
Database Type:
create or replace type xx_blobdata is varray(50) of blob;
create or replace type xx_attachedfile is varray(50) of varchar2(1000);
create or replace type xx_attachedfiletype is varray(50) of varchar2(1000);
Java Code
public class xx_attachments_mail
static String dftMime = "application/octet-stream";
static String dftName = "filename.dat";
public static oracle.sql.NUMBER
send(String from,
String to,
String cc,
String bcc,
String subject,
String body,
String SMTPHost,
oracle.sql.BLOB[] attachmentData,
String[] attachmentType,
String[] attachmentFileName);
PLSQL Wrapper
create or replace function xx_attachments_mail_send(
p_from in varchar2,
p_to in varchar2,
p_cc in varchar2,
p_bcc in varchar2,
p_subject in varchar2,
p_body in varchar2,
p_smtp_host in varchar2,
p_attachment_data in xx_blobdata,
p_attachment_type in xx_attachedfiletype,
p_attachment_file_name in xx_attachedfile) return number
as
language java name 'xx_attachments_mail.send( java.lang.String,
java.lang.String,
java.lang.String,
java.lang.String,
java.lang.String,
java.lang.String,
java.lang.String,
oracle.sql.BLOB[],
java.lang.String[],
java.lang.String[]
) return oracle.sql.NUMBER';
Actual Call:
attachment_data :=xx_blobdata();
attachment_type :=xx_attachedfiletype();
attachment_name :=xx_attachedfile();
ret_code := xx_attachments_mail_send(
p_from => '[email protected]',
p_to => '[email protected]',
p_cc => NULL,
p_bcc => NULL,
p_subject => 'testing',
p_body => 'testing..',
p_smtp_host => 'myserver.com',
p_attachment_data => attachment_data,
p_attachment_type => attachment_type,
p_attachment_file_name => attachment_name);
Everything compiles. All objects are valid in database.But when I call I get the following error:
ORA-29531: no method send in class xx_attachments_mail
ORA-06512: at "XX_ATTACHMENTS_MAIL_SEND", line 1
Can anybody point out what is wrong that I am doing.
Thanks.

Duplicate post:
Re: oracle.sql.BLOB array
Devang,
You asked:
Can anybody point out what is wrong that I am doing?Yes, I can.
VARRAY maps to "java.sql.Array" or "oracle.sql.ARRAY".
You can find more details in the JDBC Developer's Guide and Reference which is part of the Oracle documentation, as well as the JDBC sample code which can be accessed from here:
http://www.oracle.com/technology/tech/java/sqlj_jdbc/index.html
Good Luck,
Avi.

Similar Messages

  • Oracle.sql.BLOB array

    Hi,
    I have a database table(say MY_BLOB_TABLE.) having one blob column
    I want to send each blob column as an attachment to a single email i.e. I for a particular case if I have 10 qualifying rows in MY_BLOB_TABLE,I want to send all these 10 blobs as different attachments with a SINGLE email.
    I have the working code (from asktom) that allows me to send one attchment per email ..so I changed the code so that it takes array types to the things..
    here is my code:
    Database Type:
    create or replace type xx_blobdata is varray(50) of blob;
    create or replace type xx_attachedfile is varray(50) of varchar2(1000);
    create or replace type xx_attachedfiletype is varray(50) of varchar2(1000);
    Java Code
    public class xx_attachments_mail
    static String dftMime = "application/octet-stream";
    static String dftName = "filename.dat";
    public static oracle.sql.NUMBER
    send(String from,
    String to,
    String cc,
    String bcc,
    String subject,
    String body,
    String SMTPHost,
    oracle.sql.BLOB[] attachmentData,
    String[] attachmentType,
    String[] attachmentFileName);
    PLSQL Wrapper
    create or replace function xx_attachments_mail_send(
    p_from in varchar2,
    p_to in varchar2,
    p_cc in varchar2,
    p_bcc in varchar2,
    p_subject in varchar2,
    p_body in varchar2,
    p_smtp_host in varchar2,
    p_attachment_data in xx_blobdata,
    p_attachment_type in xx_attachedfiletype,
    p_attachment_file_name in xx_attachedfile) return number
    as
    language java name 'xx_attachments_mail.send( java.lang.String,
    java.lang.String,
    java.lang.String,
    java.lang.String,
    java.lang.String,
    java.lang.String,
    java.lang.String,
    oracle.sql.BLOB[],
    java.lang.String[],
    java.lang.String[]
    ) return oracle.sql.NUMBER';
    Actual Call:
    attachment_data :=xx_blobdata();
    attachment_type :=xx_attachedfiletype();
    attachment_name :=xx_attachedfile();
    ret_code := xx_attachments_mail_send(
    p_from => '[email protected]',
    p_to => '[email protected]',
    p_cc => NULL,
    p_bcc => NULL,
    p_subject => 'testing',
    p_body => 'testing..',
    p_smtp_host => 'myserver.com',
    p_attachment_data => attachment_data,
    p_attachment_type => attachment_type,
    p_attachment_file_name => attachment_name);
    Everything compiles. All objects are valid in database.But when I call I get the following error:
    ORA-29531: no method send in class xx_attachments_mail
    ORA-06512: at "XX_ATTACHMENTS_MAIL_SEND", line 1
    Can anybody point out what is wrong that I am doing.
    Thanks.

    Its already there...
    public static oracle.sql.NUMBER send();
    The code works well if I remove arrays (i.e. []) ... my problem is the mapping or VARRAY to Java datatype...
    I just read something on oracle.sql.array ....that is the solution for mapping Oracle VARRAY to Java data type... but still I dont have a working code...
    Any help is highly appreciated...

  • Oracle.sql.BLOB.setBytes() Error

    Hi,
    I'm trying to use Java to put a large array of bytes into a BLOB table column. I'm first inserting the new row with an empty_blob() and then calling select <blob_column> ... for update and getting the oracle.sql.BLOB out of the resultset. I then try to call setBytes() on this BLOB and I get the following exception:
    java.sql.SQLException: Invalid argument(s) in call: putBytes()
    at oracle.jdbc.driver.T4CConnection.putBytes(T4CConnection.java:2440)
    at oracle.sql.BLOB.setBytes(BLOB.java:916)
    I'm using Oracle XE (oracle-xe-11.2.0-1.0.x86_64.rpm), the latest ojdbc6.jar, and jboss 4.2.2 on CentOS.
    A code snippet of what I'm doing:
    ... stmt = con.prepareStatement("select blob_column from blob_table where id=? for update"); stmt.setLong(1, Id); ResultSet rs = stmt.executeQuery(); try {     if (rs.next()) {         WrappedResultSet wrappedRs = (WrappedResultSet)rs;         BLOB oracleBlob = ((OracleResultSet)wrappedRs.getUnderlyingResultSet()).getBLOB(1);         if(oracleBlob != null) {             byte[] bytes = getData();             int pos = 0;             long bytesLeft = bytes.length;             log.debug("Attempting to write " + bytes.length + " bytes to BLOB");             while(bytesLeft > 0) {                 int bytesWritten = oracleBlob.setBytes(pos, bytes, pos, MAXBUFSIZE);                 log.debug("Wrote " + bytesWritten + " bytes to BLOB");                 bytesLeft -= bytesWritten;                 pos += bytesWritten;             }         }     } } finally {     rs.close(); } ...
    Any help would be greatly appreciated!

    Welcome to the forum!
    Thanks for posting the code and the DB, JDBC and app server versions. Those are what is needed to help.
    >
    java.sql.SQLException: Invalid argument(s) in call: putBytes()
                while(bytesLeft > 0) {
                    int bytesWritten = oracleBlob.setBytes(pos, bytes, pos, MAXBUFSIZE);
                    log.debug("Wrote " + bytesWritten + " bytes to BLOB");
                    bytesLeft -= bytesWritten;
                    pos += bytesWritten;That 'Invalid argument . . .' was your clue to look at the ARGUMENT values you are passing to the method call. You could have easily done that by displaying the values to the console each time in the loop BEFORE the method call.
    This is the signature of that method in the Javadocs (edited to highlight the relevant parts):
    http://docs.oracle.com/javase/6/docs/api/java/sql/Blob.html#setBytes(long, byte[])
    >
    int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException
    Writing starts at position pos in the BLOB value; len bytes from the given byte array are written.
    Parameters:
    pos - the position in the BLOB object at which to start writing; the first position is 1
    bytes - the array of bytes to be written to this BLOB object
    offset - the offset into the array bytes at which to start reading the bytes to be set
    len - the number of bytes to be written to the BLOB value from the array of bytes bytes
    >
    This is what you are passing for 'len': MAXBUFSIZE
    Most likely that value is LARGER than the 'byte array' that you are using; perhaps it is even the MAX int size.
    That value is invalid.
    In addition each time thru the loop you increment 'pos' and use 'pos' as the 'offset' into your array. Then you once again use MAXBUFSIZE as the number of bytes to write from your array. Even if MAXBUFSIZE is less than the length of your array at some point it will likely be greater than what is left of the array.
    For example, if MAXBUFSIZE is 2 and your array length is 3 the first 'put' will put the first two bytes. Then the second put will use a 'pos' of 2 and try to put 2 more bytes; except there is only one byte left.
    Your code updates the entire BLOB value. Best practices are to use the stream methods for reading and writing BLOB/CLOB rather than the 'setBytes' method you are using. The main reason for this is performance: the stream methods write DIRECTLY to the database.
    >
    Notes:
    The stream write methods described in this section write directly to the database when you write to the output stream. You do not need to run an UPDATE to write the data. However, you need to call close or flush to ensure all changes are written. CLOBs and BLOBs are transaction controlled. After writing to either, you must commit the transaction for the changes to be permanent.
    >
    See 'Reading and Writing BLOB and CLOB Data' in the JDBC Dev Guide
    http://docs.oracle.com/cd/B19306_01/java.102/b14355/oralob.htm#i1058044
    >
    Example: Writing BLOB Data
    Use the setBinaryOutputStream method of an oracle.sql.BLOB object to write BLOB data.
    The following example reads a vector of data into a byte array, then uses the setBinaryOutputStream method to write an array of character data to a BLOB.
    java.io.OutputStream outstream;
    // read data into a byte array
    byte[] data = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    // write the array of binary data to a BLOB
    outstream = ((BLOB)my_blob).setBinaryOutputStream(1L);
    outstream.write(data);

  • Javax.sql.rowset.serial.SerialBlob cannot be cast to oracle.sql.BLOB

    Hi there,
    I'm facing this exception.
    My code:
    final ReportTemplateAttachment rta = new ReportTemplateAttachment();
    FileBlob fb = new FileBlob();
    fb.setContentType(attachmentDto.getContentType().getValue());
    fb.setCreationDate(sysDate);
    fb.setCreationUser(userId);
    final SerialBlob blob = new SerialBlob(attachmentDto.getFileVal());//it's a  byte[]
    //SerialBlob is of type javax.sql.rowset.serial.SerialBlob
    fb.setFileData(blob);
    fb.setName(attachmentDto.getFileName());
    fb.setLastUpdateDate(sysDate);
    fb.setLastUpdateUser(userId);
    fb.setLength(blob.length());
    rta.setFileBlob(fb);and the object rta will be inserted into another object.
    The variable of interest in FileBlob hbm is defined as follows:
    <property name="fileData" type="blob">
                <column name="FILE_DATA" />
    </property>where the type blob is oracle.sql.BLOB
    If I change the oracle.sql.BLOB to javax.sql.rowset.serial.SerialBlob in the hbm, I can insert but when I try to get the blob back I get a deserialize exception so this change is not an option.
    but when I save the main Object (a cascade operation) I get the following exception:
    org.springframework.jdbc.UncategorizedSQLException:
    Hibernate flushing: could not insert: [pt.sc.data.entities.FileBlob];
    uncategorized SQLException for SQL
    [insert into WP_ADMIN.file_blob (name, content_type, length, file_data, status, creation_user, creation_date, last_update_user, last_update_date, id)
    values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)];
    SQL state [null];
    error code [0];
    An SQLException was provoked by the following failure: java.lang.ClassCastException:
    javax.sql.rowset.serial.SerialBlob cannot be cast to oracle.sql.BLOB;
    nested exception is java.sql.SQLException: An SQLException was provoked by the following failure:
    java.lang.ClassCastException: javax.sql.rowset.serial.SerialBlob cannot be cast to oracle.sql.BLOBAny light on the subject?
    Thanks in advance,
    mleiria

    You don't seem to understand the difference between an object model and a database. Hibernate, being an ORM package, works on the object model and will, based on what you request it to do, generate proper SQL statements to get the database part going. But you shouldn't be thinking about databases when using Hibernate; your main focus is the object model. There is no blob, only binary data. Binary data in Java is generally handled through a byte array.
    If you want to think in databases where blobs do exist, you should be using JDBC directly, not Hibernate.
    (I'm far from being an expert in Hibernate)I would really suggest taking a few hours and reading through the manual. You don't need to be an expert but you should at least know what kind of tool you're working with.

  • Oracle.sql.BLOB and oracle.sql.STRUCT

    I'm development a application in Java with oracle, to manage media files. When I try to insert into oracle , I have this problem "oracle.sql.BLOB cannot be cast to oracle.sql.STRUCT" , and I don't know what that can be ..
    This is my code , please help with that.. If you have a smaple code of java and oracle to insert media , that will be a great help ..
    public void loadDataFromStream(OracleConnection con)
    try {
    Statement s = con.createStatement();
    OracleResultSet rs = (OracleResultSet)
    s.executeQuery("select * from blobs where id='video2.avi' for update ");
    String index = "";
    while(rs.next())
    index = rs.getString(1);
    index+="1";
    System.out.println("llego hasta aki");
    // el error esta en esta linea de abajo ...
    OrdVideo vidObj = (OrdVideo) rs.getCustomDatum(2, OrdVideo.getFactory());
    //rs.getBfile(3);///
    FileInputStream fStream = new FileInputStream("/home/jova/movie.avi");
    vidObj.loadDataFromInputStream(fStream);
    vidObj.getDataInFile("/home/jova/movie.avi");
    fStream.close();
    System.out.println(" getContentLength output : " +
    vidObj.getContentLength());
    OraclePreparedStatement stmt1 =
    (OraclePreparedStatement) con.prepareCall("update blob_col set image = ? where id = " + index);
    stmt1.setCustomDatum(1,vidObj);
    stmt1.execute();
    stmt1.close() ;
    index+="1";
    System.out.println("OK");
    catch(Exception e) {
    System.out.println("exception raised " + e);
    System.out.println("load data from stream unsuccessful");
    }

    I'm development a application in Java with oracle, to manage media files. When I try to insert into oracle , I have this problem "oracle.sql.BLOB cannot be cast to oracle.sql.STRUCT" , and I don't know what that can be ..
    This is my code , please help with that.. If you have a smaple code of java and oracle to insert media , that will be a great help ..
    public void loadDataFromStream(OracleConnection con)
    try {
    Statement s = con.createStatement();
    OracleResultSet rs = (OracleResultSet)
    s.executeQuery("select * from blobs where id='video2.avi' for update ");
    String index = "";
    while(rs.next())
    index = rs.getString(1);
    index+="1";
    System.out.println("llego hasta aki");
    // el error esta en esta linea de abajo ...
    OrdVideo vidObj = (OrdVideo) rs.getCustomDatum(2, OrdVideo.getFactory());
    //rs.getBfile(3);///
    FileInputStream fStream = new FileInputStream("/home/jova/movie.avi");
    vidObj.loadDataFromInputStream(fStream);
    vidObj.getDataInFile("/home/jova/movie.avi");
    fStream.close();
    System.out.println(" getContentLength output : " +
    vidObj.getContentLength());
    OraclePreparedStatement stmt1 =
    (OraclePreparedStatement) con.prepareCall("update blob_col set image = ? where id = " + index);
    stmt1.setCustomDatum(1,vidObj);
    stmt1.execute();
    stmt1.close() ;
    index+="1";
    System.out.println("OK");
    catch(Exception e) {
    System.out.println("exception raised " + e);
    System.out.println("load data from stream unsuccessful");
    }

  • ClassCastException while inserting in oracle.sql.BLOB

    Hi,
    I have to insert a blob data in to database . I wrote the code . I'm having a ClassCastException problem in the line oracle.sql.BLOB blob = oracle.sql.BLOB.createTemporary(st.getConnection(), false,
    oracle.sql.BLOB.DURATION_CALL); while trying to store a BLOB value I'm using Oracle 9i. (JDBC classes12.jar).
    if I use the method with a dedicated database connection that specifies the driver as oracle.jdbc.driver.OracleDriver there is no problem .
    But when I use JBoss to run , I will get ClassCastException
    I imagine that somewhere in the code of this method there is a cast of the underlying connection leading to the ClassCastException when used in conjunction with the jboss datasource. The code to save the BLOB is as follows:
    String sql = " update test set code = ? where id = ?  ";
                 BLOB   newBlob = BLOB.createTemporary(dbcon, false, BLOB.DURATION_CALL);
                  newBlob.putBytes(1,data.getBytes());
                  stmt = dbcon.prepareStatement(newsql);
                 stmt.setBlob(1, newBlob);
                 stmt.setInt(2, Studid );
                 stmt.executeUpdate();
                 stmt.close();Can any one tell me how can I get this code to work with the datasource implementation.
    Thanks

    I think this could be a problem with the class loader . Take a look at this thread It should solve your problem.
    http://forum.java.sun.com/thread.jspa?forumID=48&threadID=788715

  • Insert Blob column in the client errors ClassCastException: oracle.sql.BLOB

    Hi,
    When I try to insert and commit a Blob column(picture) I am getting the following exception.
    Is there any jar I need to add or any other setup I need to do to accept the BLOB column in the olite client database.
    500 Internal Server Error
    javax.faces.FacesException: #{backing_XXPBWorkOrderResultsCreatePGBean.saveButton_action}: javax.faces.el.EvaluationException: java.lang.ClassCastException: oracle.sql.BLOB
         at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:78)
         at oracle.adf.view.faces.component.UIXCommand.broadcast(UIXCommand.java:211)
    Caused by: java.lang.ClassCastException: oracle.sql.BLOB
         at oracle.lite.poljdbc.LiteEmbPreparedStmt.setVal(Unknown Source)
         at oracle.lite.poljdbc.POLJDBCPreparedStatement.setObject(Unknown Source)
         at oracle.lite.poljdbc.POLJDBCPreparedStatement.setObject(Unknown Source)
         at oracle.lite.poljdbc.POLJDBCPreparedStatement.setObject(Unknown Source)
         at oracle.lite.web.JupPreparedStatement.setObject(Unknown Source)
         at oracle.jbo.server.BaseSQLBuilderImpl.bindUpdateStatement(BaseSQLBuilderImpl.java:1765)
         at oracle.jbo.server.EntityImpl.bindDMLStatement(EntityImpl.java:7345)
    With regareds,
    Kali.
    OSSI.

    Here are examples if inserting into a Blob from text, file, and retrieving a blob.
    Insert into a Blob (Text)
    import java.io.FileNotFoundException;
    import java.sql.Connection;
    import java.sql.Driver;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    public class InsertBlob {
        public static void main(String[] args) throws FileNotFoundException {
            Connection con = null;
            PreparedStatement stmt = null;
            ResultSet rs = null;
            String letterText = "some letter text";
            long id = 100;
            try {
                DriverManager.registerDriver((Driver)(Class.forName("oracle.lite.poljdbc.POLJDBCDriver").newInstance()));
                try {
                    con = DriverManager.getConnection("jdbc:polite:polite", "system", "manager");
                } catch (SQLException sqle) {
                    sqle.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            try {
                stmt = con.prepareStatement("INSERT INTO BLOB_TABLE (BLOB_ID, BLOB_DATA) VALUES (?, EMPTY_BLOB())");
                stmt.setLong(1, id);
                stmt.executeUpdate();
                stmt = con.prepareStatement("SELECT BLOB_DATA FROM BLOB_TABLE WHERE BLOB_ID = ? FOR UPDATE");
                stmt.setLong(1, id);
                rs = stmt.executeQuery();
                if (rs.next()) {
                    try {
                        oracle.lite.poljdbc.BLOB oliteBlob = null;
                        oliteBlob = ((oracle.lite.poljdbc.OracleResultSet) rs).getBLOB(1);
                        byte[] byteLetterText = letterText.getBytes();
                        oliteBlob.putBytes(1, byteLetterText);
                        con.commit();
                    } catch (ClassCastException e) {
                        e.printStackTrace();
                    } finally {
                        rs = null;
                        stmt = null;
                        con.rollback();
                        con = null;
            } catch (SQLException e) {
                e.printStackTrace();
    }Insert Into a Blob (File)
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.sql.Connection;
    import java.sql.Driver;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.SQLException;
    public class InsertBlobFile {
        public static void main(String[] args) throws FileNotFoundException {
            Connection con = null;
            PreparedStatement stmt = null;
            long id = 200;
            try {
                DriverManager.registerDriver((Driver)(Class.forName("oracle.lite.poljdbc.POLJDBCDriver").newInstance()));
                try {
                    con = DriverManager.getConnection("jdbc:polite:polite", "system", "manager");
                } catch (SQLException sqle) {
                    sqle.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            try {
                stmt = con.prepareStatement("INSERT INTO BLOB_TABLE (BLOB_ID, BLOB_DATA) VALUES (?, ?)");
                stmt.setLong(1, id);
                File fBlob = new File ( "C:\\BLOB_TEST_FILE.TXT" );
                FileInputStream is = new FileInputStream ( fBlob );
                stmt.setBinaryStream (2, is, (int) fBlob.length() );
                stmt.executeUpdate();
                con.commit();
            } catch (SQLException e) {
                e.printStackTrace();
    }Retrieve from Blob (Write to file)
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.sql.Blob;
    import java.sql.Connection;
    import java.sql.Driver;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    public class RetrieveBlob {
        final static int bBufLen = 32 * 1024;
        final static String outFile = "C:\\BLOB_OUTPUT_FILE.TXT";
        public static void main(String[] args) throws IOException {
            Connection con = null;
            PreparedStatement stmt = null;
            ResultSet rs = null;
            try {
                DriverManager.registerDriver((Driver)(Class.forName("oracle.lite.poljdbc.POLJDBCDriver").newInstance()));
                try {
                    con = DriverManager.getConnection("jdbc:polite:polite", "system", "manager");
                } catch (SQLException sqle) {
                    sqle.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            try {
                stmt = con.prepareStatement("SELECT * FROM BLOB_TABLE");
                rs = stmt.executeQuery();
                while(rs.next()) {
                    int id = rs.getInt(1);
                    Blob value = rs.getBlob(2);
                    System.out.println(id + " | " + value);
                    writeBlobToFile(value);
            } catch (SQLException e) {
                e.printStackTrace();
        public static long readFromBlob(Blob blob, OutputStream out)
          throws SQLException, IOException {
            InputStream in = blob.getBinaryStream();
            int length = -1;
            long read = 0;
            byte[] buf = new byte[bBufLen];
            while ((length = in.read(buf)) > 0) {
                out.write(buf, 0, length);
                read += length;
            in.close();
            return read;
        public static long writeBlobToFile(Blob blob)
          throws IOException, SQLException {
            long wrote = 0;
            OutputStream fwriter = new FileOutputStream(outFile);
            wrote = readFromBlob(blob, fwriter);
            fwriter.close();
            return wrote;
    }

  • NullPointerException at oracle.sql.BLOB.createTemporary(BLOB.java:590)

    Hi,
    I seldom use the BLOB. Here is the coding that creates a BLOB.
    private  BLOB getBlob(byte[] str, Connection con) throws SQLException, IOException {
      BLOB blob = BLOB.createTemporary(con, true, BLOB.DURATION_SESSION);
      blob.open(BLOB.MODE_READWRITE);
      OutputStream writer = blob.getBinaryOutputStream();
      writer.write(str);
      writer.flush();
      writer.close();
      blob.close();
      return blob;
    After inserting this BLOB into database table via ojdbc, BLOB.freeTemporary() is called.
         BLOB blob = getBlob(compressedClaim,connStore);
         rsImagePstmt.setObject(4,blob);
         rsImagePstmt.executeUpdate();
         BLOB.freeTemporary( blob );
    Sometimes it's running ok and finished properly. Sometimes I got the following exception after running 2.5 hours.
    Thanks a lot for any suggestion and help.  We use oracle 10.2 and java1.4 library here.
                                      > Exception: java.lang.NullPointerException
                                      >                           at oracle.jdbc.driver.T2CConnection.checkError(T2CConnection.java:669)
                                      >                           at oracle.jdbc.driver.T2CConnection.checkError(T2CConnection.java:602)
                                      >                           at oracle.jdbc.driver.T2CConnection.createTemporaryBlob(T2CConnection.java:2039)
                                      >                           at oracle.sql.BLOB.createTemporary(BLOB.java:590)
    If I ran in the debug mode, I got the following errors after 2.5 hours:
    An unexpected exception has been detected in native code outside the VM.
    Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred at PC=0x62F0BCF4
    Function=Java_oracle_jdbc_driver_T2CStatement_t2cFetchDmlReturnParams+0x594
    Library=C:\oracle\product\10.2.0\client\BIN\ocijdbc10.dll
    Current Java thread:
      at oracle.jdbc.driver.T2CConnection.lobCreateTemporary(Native Method)
      at oracle.jdbc.driver.T2CConnection.createTemporaryBlob(T2CConnection.java:2039)
      at oracle.sql.BLOB.createTemporary(BLOB.java:590)
      at com.viant.consumer.impl.RateSheetConsumer.getBlob(RateSheetConsumer.java:386)
      at com.viant.consumer.impl.RateSheetConsumer.finishRateSheet(RateSheetConsumer.java:293)
      at com.viant.consumer.impl.RateSheetConsumer.run(RateSheetConsumer.java:156)
      at java.lang.Thread.run(Thread.java:534)
    Dynamic libraries:
    0x00400000 - 0x0040B000  C:\jdk1.4\bin\javaw.exe
    0x77220000 - 0x7735C000  C:\Windows\SYSTEM32\ntdll.dll
    0x76CE0000 - 0x76DB4000  C:\Windows\system32\kernel32.dll
    0x75620000 - 0x7566B000  C:\Windows\system32\KERNELBASE.dll
    0x758D0000 - 0x75970000  C:\Windows\system32\ADVAPI32.dll
    0x75C10000 - 0x75CBC000  C:\Windows\system32\msvcrt.dll
    0x75B20000 - 0x75B39000  C:\Windows\SYSTEM32\sechost.dll
    0x77170000 - 0x77211000  C:\Windows\system32\RPCRT4.dll
    0x75B40000 - 0x75C09000  C:\Windows\system32\USER32.dll
    0x75D50000 - 0x75D9E000  C:\Windows\system32\GDI32.dll
    0x77440000 - 0x7744A000  C:\Windows\system32\LPK.dll
    0x76F90000 - 0x7702D000  C:\Windows\system32\USP10.dll
    0x77360000 - 0x7737F000  C:\Windows\system32\IMM32.DLL
    0x75A00000 - 0x75ACC000  C:\Windows\system32\MSCTF.dll
    0x62A20000 - 0x62A2C000  C:\PROGRA~1\NETINST\NIAMH.DLL
    0x75330000 - 0x75368000  C:\PROGRA~1\SOPHOS\SOPHOS~1\SOPHOS~1.DLL
    0x77420000 - 0x77425000  C:\Windows\system32\PSAPI.DLL
    0x752B0000 - 0x752C5000  C:\Windows\system32\AMINIT32.DLL
    0x08000000 - 0x08139000  C:\jdk1.4\jre\bin\client\jvm.dll
    0x73510000 - 0x73542000  C:\Windows\system32\WINMM.dll
    0x75210000 - 0x7525C000  C:\Windows\system32\apphelp.dll
    0x10000000 - 0x10007000  C:\jdk1.4\jre\bin\hpi.dll
    0x00270000 - 0x0027E000  C:\jdk1.4\jre\bin\verify.dll
    0x00280000 - 0x00299000  C:\jdk1.4\jre\bin\java.dll
    0x002A0000 - 0x002AD000  C:\jdk1.4\jre\bin\zip.dll
    0x003D0000 - 0x003EC000  C:\jdk1.4\jre\bin\jdwp.dll
    0x002B0000 - 0x002B5000  C:\jdk1.4\jre\bin\dt_socket.dll
    0x773E0000 - 0x77415000  C:\Windows\system32\ws2_32.dll
    0x75970000 - 0x75976000  C:\Windows\system32\NSI.dll
    0x736D0000 - 0x736E0000  C:\Windows\system32\NLAapi.dll
    0x71BE0000 - 0x71BF0000  C:\Windows\system32\napinsp.dll
    0x71BA0000 - 0x71BB2000  C:\Windows\system32\pnrpnsp.dll
    0x74D50000 - 0x74D8C000  C:\Windows\System32\mswsock.dll
    0x74C10000 - 0x74C54000  C:\Windows\system32\DNSAPI.dll
    0x71BF0000 - 0x71BF8000  C:\Windows\System32\winrnr.dll
    0x71C30000 - 0x71C57000  C:\Program Files\Common Files\Microsoft Shared\Windows Live\WLIDNSP.DLL
    0x75DA0000 - 0x75DF7000  C:\Windows\system32\SHLWAPI.dll
    0x74370000 - 0x7438C000  C:\Windows\system32\IPHLPAPI.DLL
    0x74820000 - 0x74827000  C:\Windows\system32\WINNSI.DLL
    0x721E0000 - 0x72218000  C:\Windows\System32\fwpuclnt.dll
    0x71C20000 - 0x71C26000  C:\Windows\system32\rasadhlp.dll
    0x74840000 - 0x74857000  C:\ProgramData\Sophos\Web Intelligence\swi_ifslsp.dll
    0x74830000 - 0x74839000  C:\Windows\system32\VERSION.dll
    0x76090000 - 0x76CDB000  C:\Windows\system32\SHELL32.dll
    0x74810000 - 0x74815000  C:\Windows\System32\wshtcpip.dll
    0x01240000 - 0x0124F000  C:\jdk1.4\jre\bin\net.dll
    0x62F00000 - 0x62F13000  C:\oracle\product\10.2.0\client\BIN\ocijdbc10.dll
    0x08450000 - 0x084A9000  C:\oracle\product\10.2.0\client\bin\OCI.dll
    0x7C340000 - 0x7C396000  C:\Windows\system32\MSVCR71.dll
    0x61C20000 - 0x61E77000  C:\oracle\product\10.2.0\client\bin\OraClient10.Dll
    0x60870000 - 0x60956000  C:\oracle\product\10.2.0\client\bin\oracore10.dll
    0x60A80000 - 0x60B47000  C:\oracle\product\10.2.0\client\bin\oranls10.dll
    0x63690000 - 0x636A8000  C:\oracle\product\10.2.0\client\bin\oraunls10.dll
    0x60EB0000 - 0x60EB7000  C:\oracle\product\10.2.0\client\bin\orauts.dll
    0x75770000 - 0x758CC000  C:\Windows\system32\ole32.dll
    0x636B0000 - 0x636B6000  C:\oracle\product\10.2.0\client\bin\oravsn10.dll
    0x60FA0000 - 0x61098000  C:\oracle\product\10.2.0\client\bin\oracommon10.dll
    0x63430000 - 0x63457000  C:\oracle\product\10.2.0\client\bin\orasnls10.dll
    0x08C40000 - 0x091B8000  C:\oracle\product\10.2.0\client\bin\orageneric10.dll
    0x091C0000 - 0x09337000  C:\oracle\product\10.2.0\client\bin\oraxml10.dll
    0x014F0000 - 0x01501000  C:\Windows\system32\MSVCIRT.dll
    0x60960000 - 0x60A77000  C:\oracle\product\10.2.0\client\bin\oran10.dll
    0x62740000 - 0x62780000  C:\oracle\product\10.2.0\client\bin\oranl10.dll
    0x62790000 - 0x627A8000  C:\oracle\product\10.2.0\client\bin\oranldap10.dll
    0x627F0000 - 0x628FD000  C:\oracle\product\10.2.0\client\bin\orannzsbb10.dll
    0x62530000 - 0x62583000  C:\oracle\product\10.2.0\client\bin\oraldapclnt10.dll
    0x62670000 - 0x6268B000  C:\oracle\product\10.2.0\client\bin\orancrypt10.dll
    0x71230000 - 0x71237000  C:\Windows\system32\WSOCK32.dll
    0x75CC0000 - 0x75D4F000  C:\Windows\system32\OLEAUT32.dll
    0x62920000 - 0x6296D000  C:\oracle\product\10.2.0\client\bin\oranro10.dll
    0x626B0000 - 0x626B7000  C:\oracle\product\10.2.0\client\bin\oranhost10.dll
    0x62660000 - 0x62666000  C:\oracle\product\10.2.0\client\bin\orancds10.dll
    0x629C0000 - 0x629C8000  C:\oracle\product\10.2.0\client\bin\orantns10.dll
    0x09340000 - 0x096B5000  C:\oracle\product\10.2.0\client\bin\orapls10.dll
    0x07B80000 - 0x07B89000  C:\oracle\product\10.2.0\client\bin\oraslax10.dll
    0x63080000 - 0x63285000  C:\oracle\product\10.2.0\client\bin\oraplp10.dll
    0x61ED0000 - 0x61F68000  C:\oracle\product\10.2.0\client\bin\orahasgen10.dll
    0x62AB0000 - 0x62B24000  C:\oracle\product\10.2.0\client\bin\oraocr10.dll
    0x084B0000 - 0x084F9000  C:\oracle\product\10.2.0\client\bin\oraocrb10.dll
    0x73860000 - 0x73871000  C:\Windows\system32\NETAPI32.dll
    0x74B00000 - 0x74B09000  C:\Windows\system32\netutils.dll
    0x74F80000 - 0x74F99000  C:\Windows\system32\srvcli.dll
    0x73850000 - 0x7385F000  C:\Windows\system32\wkscli.dll
    0x73840000 - 0x7384F000  C:\Windows\system32\SAMCLI.DLL
    0x74BE0000 - 0x74C02000  C:\Windows\system32\LOGONCLI.DLL
    0x62980000 - 0x62991000  C:\oracle\product\10.2.0\client\bin\orantcp10.dll
    0x63520000 - 0x635BB000  C:\oracle\product\10.2.0\client\bin\orasql10.dll
    0x751E0000 - 0x751FB000  C:\Windows\system32\SspiCli.dll
    0x70890000 - 0x7089B000  C:\Windows\system32\cscapi.dll
    0x75290000 - 0x7529C000  C:\Windows\system32\CRYPTBASE.dll
    0x740B0000 - 0x740F0000  C:\Windows\system32\uxtheme.dll
    0x09B80000 - 0x09C92000  C:\jdk1.4\jre\bin\awt.dll
    0x72870000 - 0x728C1000  C:\Windows\system32\WINSPOOL.DRV
    0x09810000 - 0x09861000  C:\jdk1.4\jre\bin\fontmanager.dll
    0x0ACF0000 - 0x0ADD7000  C:\Windows\system32\ddraw.dll
    0x73AA0000 - 0x73AA6000  C:\Windows\system32\DCIMAN32.dll
    0x76DF0000 - 0x76F8D000  C:\Windows\system32\SETUPAPI.dll
    0x753F0000 - 0x75417000  C:\Windows\system32\CFGMGR32.dll
    0x75450000 - 0x75462000  C:\Windows\system32\DEVOBJ.dll
    0x73C80000 - 0x73C93000  C:\Windows\system32\dwmapi.dll
    0x0ADE0000 - 0x0AE71000  C:\Windows\system32\igdumdx32.dll
    0x0AF10000 - 0x0B3E1000  C:\Windows\system32\igdumd32.dll
    0x742C0000 - 0x742E5000  C:\Windows\system32\PowrProf.dll
    0x66150000 - 0x6621C000  C:\Windows\system32\D3DIM700.DLL
    0x76DC0000 - 0x76DEA000  C:\Windows\system32\imagehlp.dll
    0x70BF0000 - 0x70CDB000  C:\Windows\system32\dbghelp.dll
    Heap at VM Abort:
    Heap
      def new generation   total 4608K, used 291K [0x10010000, 0x10510000, 0x12770000)
       eden space 4096K,   5% used [0x10010000, 0x10046aa0, 0x10410000)
       from space 512K,  14% used [0x10490000, 0x104a2208, 0x10510000)
       to   space 512K,   0% used [0x10410000, 0x10410000, 0x10490000)
      tenured generation   total 60544K, used 56437K [0x12770000, 0x16290000, 0x30010000)
        the space 60544K,  93% used [0x12770000, 0x15e8d4b8, 0x15e8d600, 0x16290000)
      compacting perm gen  total 12800K, used 12682K [0x30010000, 0x30c90000, 0x34010000)
        the space 12800K,  99% used [0x30010000, 0x30c72900, 0x30c72a00, 0x30c90000)
    Local Time = Thu Oct 17 11:29:35 2013
    Elapsed Time = 9003
    # The exception above was detected in native code outside the VM

    Hi!
    It seems you can do this:
              try {
                   conn = new OracleDriver().defaultConnection();                graphblob = oracle.sql.BLOB.createTemporary(conn, false,oracle.sql.BLOB.DURATION_CALL); // must init
                   System.out.println("Blob is init");
              } catch ( java.sql.SQLException sEx ) {
                   throw new RuntimeException ("No connection", sEx);
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:1285601748584
    http://www.unix.org.ua/orelly/oracle/guide8i/ch09_08.htm
    /Bjoern

  • Java source / oracle.sql.BLOB.createTemporary

    Hi!
    I want to write some java-code (CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED...)
    where I want to return an image as blob.
    For doing that I have to initialize the blob in the java-code -correct?
    I see many examples like
    oracle.sql.BLOB.createTemporary(conn, false,oracle.sql.BLOB.DURATION_CALL)
    In PL/SQL there is some similar:
    dbms_lob.createtemporary(lob_loc => xmlclob, cache => TRUE, dur => dbms_lob.SESSION);
    If I have to initialize the blob in the java source, how to do that?
    I don't want an connection to an remote database, the java-code will be in the database, so can I call createTemporary without >conn<?
    (Oracle 10gR2, Windows, Linux, AIX)
    The picture will be generated calling other java-code loaded with loadjava.
    The java-source I want to write will be wrapped with PL/SQL.
    Greetings
    Bjørn

    Hi!
    It seems you can do this:
              try {
                   conn = new OracleDriver().defaultConnection();                graphblob = oracle.sql.BLOB.createTemporary(conn, false,oracle.sql.BLOB.DURATION_CALL); // must init
                   System.out.println("Blob is init");
              } catch ( java.sql.SQLException sEx ) {
                   throw new RuntimeException ("No connection", sEx);
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:1285601748584
    http://www.unix.org.ua/orelly/oracle/guide8i/ch09_08.htm
    /Bjoern

  • ClassCastException in oracle.sql.BLOB.createTemporary

    Hi,
    I'm having a ClassCastException problem using the method oracle.sql.BLOB.createTemporary while trying to store a BLOB value (JDBC classes12.jar). The problem is quite clear - if I use the method with a dedicated database connection that specifies the driver as oracle.jdbc.driver.OracleDriver there is no problem - if I use it with an Orion datasource shipped with Oracle IAS10g it gives me a ClassCastException. I imagine that somewhere in the code of this method there is a cast of the underlying connection leading to the ClassCastException when used in conjunction with the Orion datasource. The code to save the BLOB is as follows:
    oracle.sql.BLOB blob = oracle.sql.BLOB.createTemporary(st.getConnection(), false,
    oracle.sql.BLOB.DURATION_SESSION);
    blob.open(BLOB.MODE_READWRITE);
    OutputStream out = blob.getBinaryOutputStream();
    try {
    out.write((byte[])value);
    out.flush();
    out.close();
    } catch (IOException e) {
    throw new SQLException("failed write to blob" + e.getMessage());
    blob.close();
    ((oracle.jdbc.OraclePreparedStatement)(st)).setBLOB(index, blob);
    My questions are:
    (1) is it possibile to save a BLOB type with a different version of Oracle JDBC without having to rely on the Oracle specific implementation of the JDBC interface (the cast of the PreparedStatement to oracle.jdbc.OraclePreparedStatement is quite ugly and not very portable!).
    (2) if not, then how can I get this code to work with the datasource implementation for Oracle IAS.
    thanks in advance for any help.
    Dara.

    If you are using OCI driver, you may check whether using thin driver would avoid ClassCastException.

  • Using oracle.sql.BLOB data type in Java Class to pass in a Blob

    All,
    I'm trying to pass in a BLOB from PL/SQL to a Java Class, but the BLOB isn't passed correctly.
    When I check the length of the BLOB in PL/SQL its different from the length of the BLOB in java.
    I'm using DB 11g and the ojdbc5.jar file in my java classes.
    The java function uses the oracle.sql.BLOB type to get the parameter.
    The java class is loaded into the DB and called via a PL/SQL function.
    Kind regards,
    Nathalie

    The question is indeed a little ambigious defined ;o)
    When I pass the BLOB to the java method and invoke BLOB.getBytes() and then get the length of the BLOB in java the length of the BLOB is bigger than in PL/SQL.
    When I use the method 'getBinaryStream' and write this to a buffer, the code works.
    I will log a tar regarding the getBytes()-method to ask for more detailed information regarding the methods provided using the JDBC Drivers.
    Kind regards,
    Nathalie

  • Importing oracle.sql.BLOB through SQL Loader

    Hello,
    Currently the system we have creates .sql files and executes them. This takes a long time, so we're attempting to change to using SQL Loader. The one problem I'm having that I can't seem to fix is finding out how to imitate the behavior of this SQL statement through SQL Loader:
    INSERT INTO KRSB_QRTZ_BLOB_TRIGGERS (BLOB_DATA,TRIGGER_GROUP,TRIGGER_NAME)
    VALUES (oracle.sql.BLOB@515263,'KCB-Delivery','PeriodicMessageProcessingTrigger')
    I tried creating a lobfile and placing the text oracle.sql.BLOB@515263 within it this way
    INTO TABLE KRSB_QRTZ_BLOB_TRIGGERS
    WHEN tablename = 'KRSB_QRTZ_BLOB_TRIGGERS'
    FIELDS TERMINATED BY ',' ENCLOSED BY '##'
    TRAILING NULLCOLS
    tablename FILLER POSITION(1),
    TRIGGER_NAME CHAR(80),
    TRIGGER_GROUP CHAR(80),
    ext_fname FILLER,
    BLOB_DATA LOBFILE(ext_fname) TERMINATED BY EOF
    However, as expected, it merely loaded the text "oracle.sql.BLOB@515263" into the database. So does anyone have any ideas of how to imitate that insert statement through SQL Loader? The only information I have available is the string "oracle.sql.BLOB@515263", no other files or anything to aid with actually getting the binary data.
    When the .sql file is run with that insert statement in it, a 1.2kb BLOB is inserted into the database versus a 22 byte BLOB that contains nothing useful when done through SQL Loader.
    Alex

    My preference is DBMS_LOB.LOADFROMFILE
    http://www.morganslibrary.org/reference/dbms_lob.html
    did you try it?

  • Oracle.sql.BLOB ClassCastException

    Hi everyone,
    I'm trying to put a serialized Java object into Oracle. I am following the example here: http://www.oracle.com/oramag/oracle/01-may/o31asktom.html
    Here is my code:
    String sql = "begin " +
          "insert into rdm_logs (datetime, id, machine, ip_addr, action_code, tablename, comments, " +
         "row_before, row_after)" +
          "values (sysdate, ?, ?, ?, ?, ?, ?, empty_blob(), empty_blob()) " +
          "return row_before into ?; " +
      "end;";
    CallableStatement stmt = connection.prepareCall(sql);
    stmt.setString(1, username);
    stmt.setString(2, machine);
    stmt.setString(3, ip);
    stmt.setString(4, action_code);
    stmt.setString(5, table);
    stmt.setString(6, comment);
    stmt.registerOutParameter(7, java.sql.Types.BLOB);               
    stmt.executeUpdate();               
    Object o = stmt.getBlob(7);
    // output class name here
    System.out.println(o.getClass().toString());
    // cast to oracle.sql.BLOB
    oracle.sql.BLOB blob = (BLOB) o;The system output is:
    class oracle.sql.BLOB
    java.lang.ClassCastException: oracle.sql.BLOB
    As you can see, the System.out gives oracle.sql.BLOB as the object class type, so why does it throw an exception when I cast it to be the same?
    Any help would be appreciated.

    As you can see, the System.out gives oracle.sql.BLOB as the object
    class type, so why does it throw an exception when I cast it to be the same?This can happen if the two BLOB classes have been loaded with two different unrelated class loaders. Even though the names of the classes are the same there are two separate classes.
    How to fix this depends... Somehow arrange the JDBC driver to be loaded by the system class loader before any other class loader has a chance to load it?

  • Oracle.sql.BLOB.getBytes

    Hi,
    When my application( weblogiv 12c) is trying to fetch data from a BLOB column of a table, it is getting the below exception.
         at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:254)
         at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
         at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
    Caused by: java.lang.NullPointerException
         at oracle.sql.BLOB.getBytes(BLOB.java:344)
         at oracle.jdbc.driver.OracleBlobInputStream.needBytes(OracleBlobInputStream.java:181)
         at oracle.jdbc.driver.OracleBufferedStream.readInternal(OracleBufferedStream.java:169)
         at oracle.jdbc.driver.OracleBufferedStream.read(OracleBufferedStream.java:143)
         at oracle.jdbc.driver.OracleBufferedStream.read(OracleBufferedStream.java:132)
         at com.tcs.bancs.ARCH.Q_USER.Get(Q_USER.java:4026)
         ... 63 more
    I am thinking in lines of inappropriate oracle drivers. This application is currently pointed to oracle 11g database and throwing exception. However, when I swtich the database to another one (oracle 10g) with exactly the same data (to be precise, it is a replica of 11g mentioned above), it functions without any issue.
    Could anyone please help me in getting through this ..

    It does sound like a bug/incompatibility between drivers and DBMSes. Open an official support case with Oracle.

  • Oracle.sql.BLOB

    I am trying to extract a file name and its data from the database. The file data is stored as HUGEBLOB in the table. The file contains data which I found by downloading it directly from table using TOAD. However when I try to fetch the data throughh Java code :
    Blob file = rs.getBlob("file_data");
    I am getting null pointer in the next line which is:
    InputStream inputStream = ((oracle.sql.BLOB)file).getBinaryStream();
    Can anyone suggest why it is giving null exception and what is the solution to it.

    Have a go at [url http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/files/advanced/LOBSample/LOBSample.java.html]this link. Note the drawBlob method and how it 'gets' the BLOB out.

Maybe you are looking for