Inserting BLOBs

I am needing to create a BLOB object to insert into a database using a PreparedStatement. However, the BLOB locator is not working.
It is printing out "myBlob is null". Any ideas?
FileInputStream fis = new FileInputStream(myFile);
long length = myFile.length();
byte b[] = new byte[(int)length];
int bytesRead = fis.read(b);
OracleStatement stmt = (OracleStatement) con.createStatement();
OracleResultSet rs = (OracleResultSet) stmt.executeQuery ("select nameblob from test FOR UPDATE");
BLOB myBlob = (BLOB) rs.getBlob(1);
if(myBlob == null)
System.out.println("myBlob is null.");
myBlob.putBytes(0,b);
Thanks,
Jim

<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by jfisher1 ():
Thanks for the help -- that got me one step closer. Now I am getting another error:
"Invalid argument(s) in call: putBytes()"
int count = myBlob.putBytes(0,b);
When I do:
int count = myBlob.putBytes(1,b);
I get:
ORA-22920: row containing the LOB value is not locked
ORA-06512: at "SYS.DBMS_LOB", line 700
ORA-06512: at line 1
Any thoughts?
Thanks, Jim<HR></BLOCKQUOTE>
Sorry, I did not see your FOR UPDATE clause which you have already put. I think you will have to set autocommit off. It is on by default due to which it releases the lock just after acquiring it.

Similar Messages

  • Inserting blob data into database

    Hello everybody,
    I need insert blob data into database. that data i need to get from form
    can i use request.getParameter(""); for getting that file.
    Plz help how to get data from form to servlet and through callablestatement i need to insert into database.
    regards,
    Anil

    Hi,
    1) first create a form with file element
    first.jsp
    <form action="GetData" enctype="multipart/form-data" method="post">
    <input type="file" name="datafile" size="40">
    <input type="submit" value="Send">
    <input type="reset" name="Reset" value="Cancel">
    </form>
    GetData.java
    // servlet file
    public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
    res.setContentType("text/html");
    PrintWriter out = response.getWriter();
    try {
    System.setProperty( "jdbc.drivers", "com.microsoft.jdbc.sqlserver.SQLServerDriver" );
    Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver" );
    con = DriverManager.getConnection( "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=JAVATEAM;SelectMethod=cursor;User=sa;Password=urpassword" );
    PreparedStatement pst = con.prepareStatement("insert into uploads(binaryfile) values(?)");
    FileInputStream fis=new FileInputStream(request.getParameter ( "datafile" ) );
    byte[] b= new byte[fis.available()+1];
    fis.read(b);
    pst.setBytes(1,b);
    pst.executeUpdate();
    pst.close();
    con.close();
    catch(SQLException e)
    out.println ( e);
    catch (ClassNotFoundException e)
    out.println( e );
    }Here in doPost(), i create preparedstatement,
    now you to create one procedure for insert
    and by using callable statement you just call that procedure and pass this byte b as arguments,
    now its in your hands
    my idea is over.

  • Inserting Blob in PL/SQL using select from other table

    Oracle 11.1.7.0:
    I am trying to insert blob column as defined below but not able to. Is this the right way of inserting blobs?
    set serveroutput on
    spool a.dat
    DECLARE
    BEGIN
      for i in 1..2
      loop
         for j in  (select r_payload                      
                       from fp_data where payload_id=331525112)
         loop
           EXECUTE IMMEDIATE 'insert into fp_data (r_payload) values ( ' || j.r_payload || ')';
        end loop;
      end loop;
      rollback;
    END;
    exit;

    BLOB work same a CLOB
    SQL> @clob
    SQL> drop table toto;
    SQL> create table toto (
      2    A  VARCHAR2 (30)  NOT NULL,
      3    B  VARCHAR2 (30)  NOT NULL,
      4    C  clob default empty_clob()
      5  )
      6        lob(c) store as toto_name_lo(disable storage in row)
      7  ;
    SQL>
    SQL> set feedback off
    SQL> set timing on;
    SQL> prompt
    SQL> prompt Insert lob with enabled storage in row:
    Insert lob with enabled storage in row:
    SQL> insert into toto (a, b, c)
      2  select owner a, object_name b, owner || ' ' || object_name c from all_objects
      3  where rownum < 10
      4  ;
    Elapsed: 00:00:00.51
    SQL> set timing off;
    SQL> select a,b from toto;
    A                      B
    SYS                      ICOL$
    SYS                      I_USER1
    SYS                      CON$
    SYS                      UNDO$
    SYS                      C_COBJ#
    SYS                      I_OBJ#
    SYS                      PROXY_ROLE_DATA$
    A                      B
    SYS                      I_IND1
    SYS                      I_CDEF2
    SQL> drop   table fp_data;
    SQL> create table fp_data (r_payload clob);
    SQL> insert into fp_data select c from toto where a = 'SYS'     AND B = 'I_IND1';
    SQL> select count(*) from fp_data;
      COUNT(*)
          1no need for PL/SQL

  • SQLite3 and BlobsI am having trouble learning how insert blobs into SQLite

    I am having trouble learning how insert blobs into SQLite for the iphone. Is there a way to insert a blob into sqlite3 from the command line? I know it was possible with sql using
    INSERT INTO temponly(name , pic) values( 'velan',
    load_file('e:/mysql/images/Click.gif')) ;
    but I don't think load_file is supported on sqlite.
    Also, I need to insert the blobs from my iphone app. I saw a C program called eatblob.c which goes through the following just to INSERT a blob into sqlite
    1. read the jpeg image file into memory , doing appropriate malloc based on size
    2. prepare an sqlite statement with ? values
    3. bind the malloc'd memory to the ?
    4. execute an sqlite step
    etc. etc. etc....
    This is quite a bit of work just to do an INSERT ???
    The reason I'm doing this is my iphone app has a lot of tiny (20x20) images that get downloaded to the phone periodically from the server. Plus, there are a number of images that come loaded with the application. I was going to save all of these in SQLite. So, I need the command line tool to load up the initial images that come with the app, then I need code to download the images from the server and load them into the database. Of course, reading them out is necessary!
    Please help if you can!? Its late..and I'm blurry eyed from googling SQLIte3 blobs...

    Thank you for your quick reply Liam! You know, I checked the web forms list when I got that error message and the form isn't there. I was having trouble the other day when another of my forms kept getting deleted.
    Sorry if this is a stupid question (I'm a BC newbie) but I want to be sure so I can get this project finished... The proper workflow would be to create this form myself in Web Forms then insert it into the Registration - Buy template using the modules toolbox?
    Thanks to you I may get this done on time still... if my PayPal set up works

  • RegisterOutParameter - setBinaryStream - Problems inserting Blob - setRAW

    As posted in metalink (was: "Problems inserting BLOB/InputStream with ojdbc14.jar for 10g - Data size bigger than max size for this type"):
    Using setBinaryStream for large Blobs works as long as I don't register outParameters.
    Query that works: "INSERT INTO blobtest (attachment_id,name,data) VALUES(blobtest_SEQ.nextval,?,?)";
    Query that fails = "BEGIN INSERT INTO blobtest (attachment_id,name,data) VALUES( blobtest_SEQ.nextval,?,?) RETURN attachment_id INTO ? ; END;"
    The necessary tables were created by hand:
    CREATE TABLE blobtest ( NAME CHAR(255), data BLOB, attachment_id NUMBER(38))
    And
    CREATE SEQUENCE TBL_ATTACHMENT_SEQ
    The output was: <<user: SEE
    pw: QD
    instantiating oracle driver
    query: INSERT INTO blobtest (attachment_id,name,data) VALUES(TBL_ATTACHMENT_SEQ.nextval,?,?)
    uploaded no Return Parameter blob of size: 256809
    query: BEGIN INSERT INTO blobtest (attachment_id,name,data) VALUES(TBL_ATTACHMENT_SEQ.nextval,?,?) RETURN attachment_id INTO ? ; END;
    java.sql.SQLException: Datengr÷&#9600;e gr÷&#9600;er als max. Gr÷&#9600;e f³r diesen Typ: 256809
    at
    oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
    :125)
    at
    oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
    :162)
    at
    oracle.jdbc.driver.OraclePreparedStatement.setRAW(OraclePreparedState
    ment.java:5342)
    at
    oracle.jdbc.driver.OraclePreparedStatement.setBinaryStreamInternal(Or
    aclePreparedStatement.java:6885)
    at
    oracle.jdbc.driver.OracleCallableStatement.setBinaryStream(OracleCall
    ableStatement.java:4489)
    at BlobTest.writeBlob(BlobTest.java:161)
    at BlobTest.testBlob(BlobTest.java:118)
    at BlobTest.main(BlobTest.java:92)
    error: Datengr÷&#9600;e gr÷&#9600;er als max. Gr÷&#9600;e f³r diesen Typ:
    256809>>
    here the java test case:
    * Created on 25.08.2004 $Id: BlobTest.java,v 1.4 2005/04/22 11:21:11 hauser Exp $
    * as posted in metalink jdbc forum 050405 and responses by
    * [email protected]
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.InputStream;
    import java.sql.CallableStatement;
    import java.sql.Connection;
    import java.sql.Driver;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.Types;
    public class BlobTest {
    private static String FILE_NAME = "c:/temp/veryLargeFile.pdf";
    public BlobTest() {
    final static int ORACLE = 1;
    final static int MYSQL = 2;
    private String jdbcUrl = "jdbc:mysql://localhost/test?user=monty&password=greatsqldb";
    private int dbType = ORACLE;
    private Driver driver = null;
    private String user = "";
    private String pw = "";
    public static String SCHEME = "";
    public static void main(String[] args) {
    BlobTest bt = new BlobTest();
    if (args[0] != null) {
    System.out.println("dbType: " + args[0]);
    if (args[0].toLowerCase().indexOf("oracle") != -1) {
    bt.dbType = ORACLE;
    if (args[0].toLowerCase().indexOf("mysql") != -1) {
    bt.dbType = MYSQL;
    } else {
    System.out.println("not yet supported db type: " + args[0]);
    System.exit(99);
    if (args[1] != null) {
    System.out.println("jdbcUrl: " + args[1]);
    if (args[1].trim().length() != 0) {
    bt.jdbcUrl = args[1].trim();
    } else {
    System.out.println("not yet supported jdbcUrl : " + args[1]);
    System.exit(99);
    if (args.length > 2 && args[2] != null) {
    System.out.println("user: " + args[2]);
    if (args[2].trim().length() != 0) {
    bt.user = args[2].trim();
    } else {
    System.out.println("invalid user: " + args[2]);
    System.exit(99);
    if (args.length > 3 && args[3] != null) {
    System.out.println("pw: " + args[3].substring(0, 2));
    if (args[3].trim().length() != 0) {
    bt.pw = args[3].trim();
    } else {
    System.out.println("invalid filename: " + args[3]);
    System.exit(99);
    if (args.length > 4 && args[4] != null) {
    System.out.println("filename: " + args[4]);
    if (args[4].trim().length() != 0) {
    FILE_NAME = args[4].trim();
    } else {
    System.out.println("invalid filename: " + args[4]);
    System.exit(99);
    bt.setUp();
    bt.testBlob();
    public void setUp() {
    try {
    if (this.dbType == ORACLE) {
    System.out.println("instantiating oracle driver ");
    this.driver = (Driver) Class.forName(
    "oracle.jdbc.driver.OracleDriver").newInstance();
    } else {
    this.driver = (Driver) Class.forName("com.mysql.jdbc.Driver")
    .newInstance();
    if (this.driver == null) {
    System.out.println("oracle driver is null");
    System.exit(88);
    DriverManager.registerDriver(this.driver);
    } catch (Exception e) {
    e.printStackTrace();
    System.out.println("error: " + e.getMessage());
    public void testBlob() {
    try {
    this.writeBlob();
    } catch (Exception e) {
    e.printStackTrace();
    System.out.println("error: " + e.getMessage());
    * testfunction
    private void writeBlob() throws Exception {
    Connection conn = null;
    PreparedStatement pStmt = null;
    CallableStatement cStmt, cStmt2 = null;
    InputStream in = null;
    try {
    File file = new File(BlobTest.FILE_NAME);
    in = new FileInputStream(file);
    conn = DriverManager.getConnection("jdbc:" + this.jdbcUrl,
    this.user, this.pw);
    conn.setAutoCommit(false);
    String queryWorks = "INSERT INTO " + SCHEME
    + "blobtest (attachment_id,name,data) VALUES(" + SCHEME
    + "TBL_ATTACHMENT_SEQ.nextval,?,?)";
    cStmt = conn.prepareCall(queryWorks);
    System.out.println("query: " + queryWorks);
    cStmt.setString(1, file.getAbsolutePath());
    in = new FileInputStream(file);
    cStmt.setBinaryStream(2, in, (int) file.length());
    cStmt.execute();
    System.out.println("uploaded no Return Parameter blob of size: "
    + file.length());
    conn.commit();
    String queryFails = "BEGIN INSERT INTO " + SCHEME
    + "blobtest (attachment_id,name,data) VALUES(" + SCHEME
    + "TBL_ATTACHMENT_SEQ.nextval,?,?)"
    + " RETURN attachment_id INTO ? ; END;";
    cStmt2 = conn.prepareCall(queryFails);
    System.out.println("query: " + queryFails);
    cStmt2.setString(1, file.getAbsolutePath());
    in = new FileInputStream(file);
    cStmt2.setBinaryStream(2, in, (int) file.length());
    cStmt2.registerOutParameter(3, Types.INTEGER);
    cStmt2.execute();
    System.out.println("uploaded blob of size: " + file.length()
    + " - id: " + cStmt2.getInt(3));
    conn.commit();
    } catch (Exception e) {
    e.printStackTrace();
    System.out.println("error: " + e.getMessage() + "\nname: "
    + BlobTest.FILE_NAME);
    if (conn != null) {
    try {
    conn.rollback();
    } catch (Exception e1) {
    throw e;
    } finally {
    if (in != null) {
    try {
    in.close();
    } catch (Exception e) {
    if (pStmt != null) {
    try {
    pStmt.close();
    } catch (Exception e) {
    if (conn != null) {
    try {
    conn.close();
    } catch (Exception e) {
    and the batch file I use to start:
    @setlocal
    @echo off
    rem $Id: runBlobTest.bat,v 1.2 2005/04/21 15:06:22 hauser Exp $
    set classpath=../WEB-INF/classes;../WEB-INF/lib/ojdbc14.jar;
    echo JAVA_HOME: %JAVA_HOME%
    set JAVA_HOME=C:\PROGRA~1\Java\j2re1.4.1_02\
    echo classpath: %classpath%
    set javaCmd=C:\PROGRA~1\Java\j2re1.4.1_02\bin\java
    %javaCmd% -version
    %javaCmd% BlobTest "oracle" "oracle:thin://@ORADB.yourdomain.COM:1521:t300" "username" "password" "C:\Temp\veryLargeFile.pdf"
    endlocal

    Apparently, this is partially known - with a different stacktrace though:
    <<From: Oracle, Anupama Srinivasan 25-Apr-05 07:15
    Can you please check on Bug:4083226?
    Using the RETURNING Clause is not supported with JDBC. You could embed the statement in PL/SQL Block as in Metalink Note 124268.1 - JDBC Support for DML Returning Clause.
    The Enhancement Request filed on this issue is being considered for Release 10.2
    >>
    And my answer to it.
    Using the RETURNING Clause is not supported with JDBC.This is strange, with just "emptyblob()", it DOES work.
    I guess, our work-around that hopefully is more portable than embedding a "PL/SQL Block" will be to
    1) create the record with an empty blob,
    2) update the blob in a second statement (now, a RETURNING statement is no longer needed)

  • Please HELP!!! I try to insert BLOB to Oracle

    Please help, I try to insert BLOB to Oracle.
    Here is my sample code. Basically what i tried to do is to to try to insert an image file to Oracle.
    But it did not work. If you have a sample code that works, please give me.
    Thanks,
    Tom
    try
    out.println ("Done");
    dbCon=trans.getConnection();
    dbCon.setAutoCommit(false);
    stmt1.execute ("update emorytest.PHYSICIANFOTO set FOTO=empty_blob() where name = 'foobar'");
    stmt = dbCon.prepareCall("SELECT FOTO from emorytest.PHYSICIANFOTO where name='foobar' for update");
    stmt.execute();
    rset = (OracleResultSet)stmt.getResultSet();
    rset.next();
    BLOB bdata = rset.getBLOB("test.jpg");
    os = bdata.getBinaryOutputStream();
    os.write(bdata);
    os.flush();
    os.close();
    dbCon.commit();
    dbCon.close();
    catch (Exception ex)
    ex.printStackTrace();

    Well, the obvious problem is that your "getBLOB" call ought to access the field by the field name "FOTO" not by a file name. Then you need to open an FileInputStream for the image before copying it to the blob's output stream.
    In my opinion BLOB and CLOB handling is jdbc is a confusing mess.

  • Inserting BLOBs Programmatically

    Is it possible to insert BLOBs programmatically?
    http://java.sun.com/docs/books/tutorial/jdbc/jdbc2dot0/inserting.html
    has details on this, but it appears to be at odds with the "empty_blob()" mechanism used by oracle, which requires an explicit insert statement.
    Thanks,
    Sanjay

    Although jdbc can't immediately see how the Blob/Clob needs to be implemented the database implementors should. The sequence should be as you suggest: create a new blob, write the data to it then store the OID in the database with a PreparedStatement.
    Because the Blob needs to be database implementation specific new Blobs should be created from the Connection object. In the typical case writing to the Blob should write straight to the database. Copying block values from one record to another should just involve copying the OID.
    As I read the Blob class description it should mean that the actual data isn't moved to or from the client unless you open a stream on it.
    Looking at the postgres implementation source it's pretty crude, in fact whereas retrieving a blob works as I suggested; no reads from the database until you open the stream, when you write the blob back to the database it's creating a new OID every time. I'd assumed it would retrieve the OID from the Blob you passed to PreparedStatment.setBlob actually it creates a new OID and copies the data byte by byte (icky).
    Looks, in fact, as if I can create a fake Blob with nothing but a getBinaryStream method.
    setBinaryStream/setAsciiStream doesn't work properly because it seems to decide whether the field is a blob purely based on the implementation version of postgres, without regard for the field type. (I suppose you can't judge the field type in a PreparedStatement).

  • Inserting blob images in a database

    Hi there can anyone tell me how to insert a blob image into a table; can you actually give me an example
    thanks

    use DBMS_LOB.LOADFROMFILE.
    PROCEDURE LOADFROMFILE
    Argument Name                  Type                    In/Out Default?
    DEST_LOB                       BLOB                    IN/OUT
    SRC_LOB                        BINARY FILE LOB         IN
    AMOUNT                         NUMBER(38)              IN
    DEST_OFFSET                    NUMBER(38)              IN     DEFAULT
    SRC_OFFSET                     NUMBER(38)              IN     DEFAULT

  • Error while inserting BLOB value in the database

    I am trying to insert a BLOB value in the database. This action results in the following exception:
    java.sql.SQLException: ORA-22925: operation would exceed maximum size allowed for a LOB value
    The method i am using is as follows:
    public void insertBlob(Connection Con, StringBuffer Message)throws SQLException
    String Query = "INSERT INTO MSGBLOCKS (MSGDB_ID, MSGBLOCKTYPE, MESSAGE) VALUES (20, 1 , ?)";
    PreparedStatement PS = Con.prepareStatement(Query);
    byte[] bytes = new String(Message).getBytes();
    ByteArrayInputStream bi = new ByteArrayInputStream(bytes);
    PS.setBinaryStream(1, bi, bytes.length);
    PS.executeUpdate();
    The manifest file of ojdbc14.jar being used is: 10.1.0.5.0 and I am using jdk 1.4.
    Also the message being tried to insert is of 9 Kb only.
    Any help would be greatly appreciated.
    Thanks!!!

    Did you check if the Message is having only that small 9kb of data? also check the maximum allowed size for that column in the Oracle DB, the size can be restricted to 8Kb also.
    Edited by: DynamicBasics on Jul 28, 2010 5:54 PM

  • ERROR WHILE INSERTING BLOBS AS PARAMETERS OF EXISTING STORED PROCEDURE

    I have 2 simple tables to keep large application data (as XMLDOCUMENT in one table and BLOB in another):
    SQL> desc bindata_tbl;
    Name Null? Type
    BDATA_ID NOT NULL NUMBER(10)
    BDATA NOT NULL BLOB
    SQL> desc metadata_tbl;
    Name Null? Type
    MDATA_ID NOT NULL NUMBER(10)
    MDATA NOT NULL SYS.XMLTYPE
    and stored preocedure to input new data into those tables:
    "SP_TEST_BIN_META_DATA"
    i_MetaData in METADATA_TBL.MDATA%TYPE,
    i_BinData in BINDATA_TBL.BDATA%TYPE
    as
    begin
    if i_MetaData is not null then
    insert into METADATA_TBL (MDATA_ID, MDATA)
    values (METADATA_SEQ.nextval, i_MetaData);
    end if;
    if i_BinData is not null then
    insert into BINDATA_TBL (BDATA_ID, BDATA)
    values (BINDATA_SEQ.nextval, i_BinData);
    end if;
    COMMIT;
    -- Handle exceptions
    EXCEPTION
    WHEN OTHERS THEN
    ROLLBACK;
    RAISE;
    end;
    I communicate with database from .Net application using "Oracle.DataAccess 10.1.0.200 (Runtime version v1.0.3705)" component.
    Following procesure is a [simplified] examlple of the code I use, which demonstrates the errors while inserting XMLDOCUMENT and BLOB values simultaneously.
    In my application those should be quite big objects (~200 K XML and ~5-25M binary image data), but following sample keeps failing even with very small-sized objects:
    Line Number
    1          private void PureTest()
    2          {
    3               OracleConnection conn = null;
    4               OracleTransaction tx = null;
    5               OracleCommand command = null;
    6
    7               try
    8               {
    9                    // Open connection
    10                    string strConn = "Data Source=AthenaWf; User ID=AthenaWf; Password=Poseidon";
    11                    conn = new OracleConnection( strConn );
    12                    conn.Open();
    13
    14                    // Begin transaction (not sure if really needed)
    15                    tx = conn.BeginTransaction();
    16
    17                    // Create command
    18                    string strSql = "SP_TEST_BIN_META_DATA";
    19                    command = new OracleCommand();
    20                    command.Connection = conn;
    21                    command.CommandText = strSql;
    22                    command.CommandType = CommandType.StoredProcedure;
    23
    24                    // Create parameters
    25                    // 1) XmlType parameter
    26                    string strXml = "<?xml version=\"1.0\"?><configuration testValue=\"123456789\"/>";
    27                    XmlDocument xmlDoc = new XmlDocument();
    28                    xmlDoc.LoadXml( strXml );
    29                    OracleXmlType oraXml = new OracleXmlType( conn, xmlDoc );
    30                    //oraXml = null;
    31                    //
    32                    OracleParameter xmlPrm = new OracleParameter();
    33                    xmlPrm.ParameterName = "i_MetaData";
    34                    xmlPrm.Direction = ParameterDirection.Input;
    35                    xmlPrm.OracleDbType = OracleDbType.XmlType;
    36                    xmlPrm.Value = oraXml;
    37                    command.Parameters.Add( xmlPrm );
    38
    39                    // 2) Blob type
    40                    byte[] buf = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    41                    OracleBlob oraBlob = new OracleBlob( conn, true );
    42                    //oraBlob.Write( buf, 0, buf.Length );
    43                    oraBlob = null;
    44                    //
    45                    OracleParameter blobPrm = new OracleParameter();
    46                    blobPrm.ParameterName = "i_BinData";
    47                    blobPrm.Direction = ParameterDirection.Input;
    48                    blobPrm.OracleDbType = OracleDbType.Blob;
    49                    blobPrm.Value = oraBlob;
    50                    command.Parameters.Add( blobPrm );
    51
    52
    53                    // Execute command finally
    54                    command.ExecuteNonQuery();
    55                    tx.Commit();
    56               }
    57               catch( Exception ex )
    58               {
    59                    // Clean-up
    60                    if( command != null )
    61                    {
    62                         command.Dispose();
    63                    }
    64                    if( tx != null )
    65                    {
    66                         tx.Dispose();
    67                    }
    68                    if( conn != null )
    69                    {
    70                         conn.Dispose();
    71                    }
    72
    73                    // Display error message
    74                    MessageBox.Show( ex.Message, "Error" );
    75               }
    76          }
    If I try insert only XMLDOCUMENT object (lines 30, 42 are commented out, 43 IS NOT) - everything is OK.
    If I try to insert only BLOB object (lines 30, 42 are NOT COMMENTED OUT, line 43 is commented out) - everything is OK again.
    If I try to insert them both having some values (lines 30, 43 are commented out, 42 is not commented out) - it fails right on "command.ExecuteNonQuery();" (line 54)
    with the following exception:
    "ORA-21500: internal error code, arguments: [%s], [%s], [%s], [%s], [%s], [%s], [%s], [%]".
    Even when I nullify oraBlob before assigning it to OracleParameter value (line 30 is commented out, line 42 and 43 are not) I have the same exception.
    XMLDOCUMENT and DLOB data logically are very coupled objects (in my application), so I really want to insert them simultaneously in one stored procedure in transactional way.
    Is it bug of drivers, server, .net environment, or I miss something in implementation?
    PS. In some articles on Oracle web and in MSDN site I found a mention about necessity of wrapping all write/update operations in a transaction, while working with temporary LOBs. I use it here, but it does not look like changing anything.

    Hello,
    I tested your code with the 10.1.0.4.0 ODP and 10.1.0.4.0 Client and it worked fine.
    Can you please apply the 10.1.0.4.0 patches for both ODP and client to see if this resolves the issue for you.
    Here is the output from the same execution of the ODP application you provided as a testcase. These rows were inserted at the same time when I executed the application and passed the data as parameters to the SP you provided.
    Results of Testing with 10.1.0.4.0
    ==========================
    SQL> select count(*) from BINDATA_TBL
    2 ;
    COUNT(*)
    1
    SQL> select count(*) from METADATA_TBL;
    COUNT(*)
    1
    SQL> select dbms_lob.getlength(bdata) from BINDATA_TBL;
    DBMS_LOB.GETLENGTH(BDATA)
    10
    SQL> select mdata from METADATA_TBL;
    MDATA
    <?xml version="1.0"?><configuration testValue="123456789" />

  • Sql server bulk insert blob filename parameter

    My problem SQL script:
    declare @filepath varchar(100)
    set @filepath = 'E:\foto\1.jpg'
    INSERT INTO [dbo].[MsQuestions] ([TestCategoryID], [LevelID], [TestTypeID], [QuestionText], [QuestionImg])
    select  1 , 1, 8, 'data gambar',BulkColumn FROM OPENROWSET(BULK   @filepath , SINGLE_BLOB)
    thanks.
    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.SqlClient" %>
    <%
    string sConn = @"server=.; database=OnlineTesting; Integrated Security=True";
    SqlConnection objConn = new SqlConnection(sConn);
    objConn.Open();
    string sTSQL = "exec sp_filenamea";
    SqlCommand objCmd = new SqlCommand(sTSQL, objConn);
    objCmd.CommandType = CommandType.Text;
    SqlDataReader dr = objCmd.ExecuteReader();
    dr.Read();
    Response.BinaryWrite((byte[])dr["QuestionImg"]);
    objConn.Close();
    %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
    <title>Exec SP</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    </div>
    </form>
    </body>
    </html>

    Perhaps this 
    http://dimantdatabasesolutions.blogspot.co.il/2009/05/how-to-uploadmodify-more-than-one-blob.html
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

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

  • Inserting blob image into table

    ora.gif, image001.jpeg are the image names .these are stored in the location D:\oracle\Bfiles
    create directory BFILE_FILES as ‘D:\oracle\Bfiles';
    i want to insert the 2 images into table using blob
    how to create the table and how to insert and how to test that image is inserted or not

    Tom Kyte has it all Here

  • Insert BLOB problem

    Hi:
    I'm using oracle 8.1.6 on SunOS 5.7.
    I tried to insert a MS Word file into a blob column, but failed.
    Following are what I did:
    create table test
    (id number primary key,
    text blob
    insert into test (id,text) values (1,empty_blob());
    create directory filedir as '/home/mydir';
    Declare
    lobd BLOB;
    fils BFILE;
    BEGIN
    fils := BFILENAME('filedir','test.doc');
    SELECT text INTO lobd FROM test WHERE id = 1 FOR UPDATE;
    dbms_lob.fileopen(fils, dbms_lob.file_readonly);
    dbms_lob.loadfromfile(lobd, fils, dbms_lob.getlength(fils));
    COMMIT;
    dbms_lob.fileclose(fils);
    END;
    I got error message:
    DECLARE
    ERROR at line 1:
    ORA-22285: non-existent directory or file for FILEOPEN operation
    ORA-06512: at "SYS.DBMS_LOB", line 475
    ORA-06512: at line 7
    The file test.doc is at that directory /home/mydir. I tried to replace
    'filedir' with '/home/mydir' in the line
    fils := BFILENAME('filedir','test.doc');
    but still no success.
    Could anyone give me some advices?
    Thanks,
    George

    Hi Omar,
    Could anyone tell me how to insert a file (say a word doc., or a PDF or a text document) into a column of a table of type BFILE or BLOB. I know that it is possible to map to the physical file on the filesystem thru logical directory creation. But, would like to know how to insert a file into the column and use it later for retireval, string searching, etc. from the queries. Is it thru SQL*Loader? Could u explain me(with example, if poss.) how to do this with the loader utility?
    Pls guide me thru this.
    Thanks!
    Regards,
    Sanjay

  • Insert BLOB

    I have successfully uploaded a file and stored in a BLOB column and can retrieve and view it from the web, but I have a lot of documents that I need inserted for reference. I don't mind ftp'ing them to the UNIX box but I'm not sure of the PL/SQL to use to read the files from the OS and store in the database.
    Any ideas?

    What kind of application are you using? Forms web or c/s? Something else? Search the appropriate forum for the answer, as there are already many examples.

Maybe you are looking for

  • External display won't go away unless I restart my MacBook

    If I connect an external display to my MacBook it still think it's connected after the cable is disconnected. When I use "Detect Displays" it still thinks the external is connected. The only way I can get the computer back to using only 1 monitor is

  • Cover-flow and Album-art problems

    On cover-flow, sometimes background album-art will jump ahead of the viewed (center) album. (iPhone 5, iOS 6.0.1) can I fix this? Also, in the lock screen (same iPhone) the album-art will not be in the center of the screen, but down about half way th

  • Validation problem when update a row in OAF

    created a application using OAF. No problem to create a row, when tried to update the row, received the following error message: oracle.jbo.RowValException: JBO-27012: Row validation method validation() failed for row with key oracle.jbo.Key 2) Steps

  • Can we post to two real cost objects?

    how many cost objects can we use at the time of posting? and how many real objects can we use at the time of posting? as far as my knowledge we can use one real object. but in one interview , the interviewer said that we could use two real objects? i

  • Can't complete the download using my cable modem

    I did try three times and each time wasted over one hour to download the "Oracle9i Database Release 2 Enterprise/Standard/Personal Edition for Windows NT/2000/XP". The transfer died at less than 50% of file 92010NT_Disk1.zip. Is there anyone download