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

Similar Messages

  • 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

  • ClassCast Exception at oracle.sql.BLOB.createTemporary

    Hi...
    I am facing a problem that when I am trying to open a temporary BLOB, I am getting a ClassCastException. Below is a part of stack trace:
    java.lang.ClassCastException: weblogic.jdbc.rmi.SerialConnection_weblogic_jdbc_rmi_internal_ConnectionImpl_weblogic_jdbc_wrapper_PoolConnection_oracle_jdbc_driver_T4CConnection_1034_WLStub
    at oracle.sql.BLOB.createTemporary(BLOB.java:684)
    I am using Weblogic 10.3.4.0 with Jrocket 1.6 Update 24 in my JAVA_HOME.
    Initially I thought this is a JDBC driver problem, then I tried with ojdbc14.jar, ojdbc5.jar, ojdbc6.jar but same result.
    With more googling I found some other reasons like:
    "Problem which seems to be that despite the fact that method BLOB.createTemporary takes a java.sql.Connection object as a parameter, it only works if the Connection is an oracle.jdbc.driver.OracleConnection object. If it's not an oracle.jdbc.driver.OracleConnection, then I get a ClassCastException. "
    I also found out that the problem happens because when I run my code in Weblogic and get the database connection via a DataSource object that I lookup via JNDI, the connection is not a real OracleConnection object, but an object that wraps the real OracleConnection.
    Now the question is how do I solve this? In My DataSource->Connection Pool-> I have unchecked the "Wrap Data Types" and it still it doesn't work.
    Not using Connection Pool is out of the question as this is not a viable solution.
    Feel free to ask me whatever details you want, but need a urgent solution for this.
    Regards,
    Priyam

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

  • 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.

  • 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

  • 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

  • Java.lang.AbstractMethodError: oracle.sql.BLOB.setBytes

    Hi ,
    When I deployed an application ( In Oracle 10g )that uses oracleresultset i am getting an error as follows java.lang.AbstractMethodError: oracle.sql.BLOB.setBytes
    anybody has a clue ?
    Vishnu

    Hi Vishnu,
    I got the same error, and also when trying blob.setBinaryStream(1L);
    By me the DB is an 8.1.6 and the JDBC Driver I tried are both the new 10.1 and older ones.
    Did you solve your problem ? In which case I would be interested in a solution. A work around seems to be the blob.getBinaryOutputStream() method, but this is a problem for me since it is not portable.
    Regards
    Michele

  • 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;
    }

  • Oracle.sql.BLOB.freeTemporary() is not freeing TEMP space in the database

    Hi Folks,
    We are using oracle.sql.BLOB to store some file information into the database.
    Allocation of the temp space is done as below
    BLOB blob=BLOB.createTemporary(conn, false, BLOB.DURATION_SESSION); // this results in the usage of TEMP space from database
    And subsequent release is done as below
    blob.freeTemporary(); // this should have release the space from the database.
    This is on Oracle 10g, Java 1.6, ojdbc6.jar There are no exceptions. Even a simple program results in the same.
    Anybody faced something similar? Any pointers would be really appreciated.
    Thanks,
    Deva
    Edited by: user10728663 on Oct 11, 2011 5:33 AM

    Thanks a lot for the information.
    Memory is fine. And I am able to reproduce this within the scope of a simple example as well.
    Would you have any reference to the thread which had earlier reported this as a bug. I tried a reasonable amount of search in the forum, but no success.
    Thanks very much for any pointers.

  • 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");
    }

  • 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 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.

  • 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

  • Four iPhones one apple id

    I'm sorry to ask a question that has already been covered but I have many different devices and so finding the solution seems really complicated. We have 4 iphones,1 ipad ,2 ipad minis and 2 MacBooks. We would like to share music purchases, apps and

  • HP Officejet Pro L7780

    My printer has decided I need new cartridges, and will not print without them. I have already changed out the cartridges and always use HP products. Now the ink has run through my printer to the mother board and out the power connection. Anyone else

  • Triggers on tables in the Oracle BAM DataObjects

    Hi there. I am using Monitor Express in Oracle BAM 11.1.1.4 (PS3) and the field LATEST from dataobject BIdefault_composite_component is working as desired. I want to use the same solution in Oracle BAM 11.1.1.3, but the field "_LATEST" was not filled

  • How to insert into database using jsp

    sir the code below is to enter the items in the database but it is giving the error .......of null................. <!-- JAI SHRI RAM --> <%@ page import="java.sql.*" %> <html> <head><title>JAI SHRI RAM</title></head> <body> <% String url = "jdbc:odb

  • Performance in a case statement

    Hi I have a query like this - SELECT MAX(CASE WHEN field1 = 'xyz' THEN field2 END) AS alias1, MAX(CASE WHEN field2 = 'abc' THEN field2 END) AS alias2 FROM table1 WHERE field1 = 'xyz' and field2 = 'abc' and some fixed condition Please note that the co