Problem with inserting two BLOBs into a table using setBinaryStream

DBMS 9.2.0.1.0, Oracle JDBC driver 10.1.0.2.0
The following code insert in one INSERT two BLOBs
into two columns using PreparedStatement.setBinaryStream(). When the size of the of at least one blob exceeds
some limit (? 2k, 4k ?), the values are swapped and
inserted into wrong columns.
Please, is this a problem in JDBC driver?
====================================================
import java.io.ByteArrayInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
* Test - two BLOBs swapped problem.
* If size of the blob is larger that some treshold, they are swapped in the database.
public class BlobSwapTest {
private static Connection getConnection() throws SQLException {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException cnfe) {
throw new SQLException("ClassNotFoundException: " + cnfe.getMessage());
return DriverManager.getConnection("jdbc:oracle:thin:@//HOST:1521/DB", "USER", "PSWD");
private static void createTable() throws SQLException {
Connection conn = getConnection();
Statement stmt = null;
try {
stmt = conn.createStatement();
try {
stmt.execute("DROP TABLE BlobTest2");
} catch (SQLException e) {
System.err.println("Table BlobTest2 was not deleted: " + e.getMessage());
stmt.execute(
"CREATE TABLE BlobTest2 ("
+ " pk VARCHAR(512), "
+ " blob BLOB, "
+ " blobB BLOB, "
+ " PRIMARY KEY (pk)"
+ ")"
} finally {
try {
if (stmt != null) stmt.close();
} finally {
conn.close();
public static void main(String[] args) throws SQLException {
createTable();
Connection conn = getConnection();
PreparedStatement pstmt = null;
try {
conn.setAutoCommit(false);
pstmt = conn.prepareStatement("INSERT INTO BlobTest2 VALUES (?,?,?)");
final int size = 5000; // change the value to 500 and the test is OK
byte[] buf = new byte[size];
byte[] buf2 = new byte[size];
for (int i = 0; i < size; i++) {
buf = 66;
buf2 = 88;
pstmt.setString(1, "PK value");
pstmt.setBinaryStream(2, new ByteArrayInputStream(buf), size);
pstmt.setBinaryStream(3, new ByteArrayInputStream(buf2), size);
pstmt.executeUpdate();
conn.commit();
} finally {
if (pstmt != null) pstmt.close();
conn.close();
====================================================

See my response in the JVM forum.

Similar Messages

  • Inserting multiples rows into a table using function or procedure..

    How do i insert multiples rows into a table using function or procedure?
    Please provide me query..

    Use FORALL bulk insert statement...
    eg:
    procedure generate_test_data as
    type cl_itab is table of integer index by pls_integer;
    v_cl_itab cl_itab;
    type cl_vtab is table of varchar2(25) index by pls_integer;
    v_cl_vtab cl_vtab;
    type cl_dtab is table of date index by pls_integer;
    v_cl_dtab cl_dtab;
    begin
    for i in 1.. 100 loop
              v_cl_itab(i):= dbms_random.value(1,1000);
              v_cl_vtab (i):=dbms_random.string('a',20);
              v_cl_dtab (i):=to_date(trunc(dbms_random.value(2453737, 2454101)),'j');          
         end loop;
         forall i in v_cl_itab.first .. v_cl_itab.last
              execute immediate 'insert into test_order values( :n, :str , :dt ) ' using v_cl_itab(i), v_cl_vtab (i), v_cl_dtab (i);          
         commit;
    end;

  • Inserting an image into a table using the iPad?

    I am trying to make an evidence table in pages. I need to insert photographs into a table, next to the related statement. Is it possible to insert a photograph into the table on an iPad as I obviously don't have the 'command' button that others are using. If this is possible I want to be able to insert the picture as a predefined size?

    Hi,
    Yes, you can do this by using the Word Edit Cell VI under Report Generation>>Word Specific>>Word Tables in your block diagram functions pallette.  After creating a table, you can edit specific cells and send the file path of the image saved on your computer to that specific cell.  I put together an example that I've attached here as well to help you out with this.
    Regards,
    Austin S.
    National Instruments
    Academic Field Engineer
    Attachments:
    RGTWordImageInTable.vi ‏14 KB

  • How can I Insert a BLOB into a Table from Java?

    I have a Java class that creates an xml file from data in a non-sql data source. After it successfully creates and saves the file it inserts a record into an Oracle table to log the fact that an xml file was created.
    Now the guy in the warehouse wants to get an email with the file attached. I have been looking into the apex_mail package, because we already have a procedure using htmldb_mail. However, that procedure is on our old server with HTMLDB 1.6 and it is not sending any attachments.
    I think I have most of the apex_mail worked out, but I'm stuck on the blob thing. This is what I have so far:
    * The Java program creates a String object called xmlDoc
    * After xmlDoc is fully constructed, the file is written to the (Linux) server. This is accomplished with the following:
    // writing the xmlDoc
    fileDest = "/home/ewh/XMLOUT/";
    fileName = "OrderEW_"\+orderNbr\+"_"\+ticketNbr\+".xml";
    FileWriter fstream = new FileWriter(fileDest+fileName);
    BufferedWriter out = new BufferedWriter(fstream);
    out.write(xmlDoc);
    out.close();
    * Next I insert a record into the log file with:
    // Add a record to the Oracle order_email table to let the mail process know that
    // a new xml file is ready to be e-mailed to operations.
    emailLogInsertQuery = " insert into ewh.order_email ( file_name, create_date ) ";
    emailLogInsertQuery += " values ('"\+fileName\+"', sysdate)";
    oraAction = oraStmt.executeUpdate( emailLogInsertQuery );
    All of this is working fine so far. Now, I have added a blob type field to the order_email table, but I have no idea what to stick in there so that I have everything that apex_mail.add_attachment needs.
    Here's a description of the order_email table:
    SQL> desc ewh.order_email;
    Name Type Nullable Default Comments
    FILE_NAME VARCHAR2(30) Y
    FILE_BLOB BLOB Y
    CREATE_DATE DATE Y
    SEND_DATE DATE Y
    Thanks ever so much,
    Gregory
    Edited by: Canis Polaris on Jun 10, 2009 2:10 PM - Added escapes as necessary to show the plus signs around Java variables.

    Hi,
    From within APEX one can enter blob data in database tables, view the data and also update the data. Also one can send a blob attachment in an email.
    May be you can follow a combination of the following OBEs to insert BLOB data and send BLOB data from APEX:
    http://www.oracle.com/technology/obe/apex/apex31nf/apex31blob.htm
    http://www.oracle.com/technology/obe/apex/apex31nf/apex31email.htm
    -Priyanka

  • How do you insert new records into multiple tables using the same unique primary key?

    I’ve created a PHP site and MySQL server using a free app called XAMPP.  I have successfully created a form in Dreamweaver that will write data to a (name) table in the SQL database.  Here’s my question: How do you write to two (or more) tables in the same database and pass the same primary key to both tables?  In the SQL database, I defined the first field as ID and set it as the primary key with auto update.  So, when you insert a new record, it creates a unique primary key for that record.  In my form, I’m capturing info that needs to be stored to two tables at the same time; a Name table and Address table. Since the Name and Address tables use the ID field as the primary key, I believe I will need to pass the ID value from the Name table to the insert of the Address table to insure they both have the same primary key, right?

    No. You probably need the primary key from one table to be a foreign key in the other tables. In any case, I believe you can use two methods to obtain the auto generated key. First with SQL:
    http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html
    And the other using a PHP function:
    http://us3.php.net/mysql_insert_id

  • Inserting multiple rows into a table (using sequences)

    Hi!
    I want to insert multiple rows into a db table, but I don't know how.
    I know how to insert 1 row using a sequence:
    I put all the fields in the jsp form's page and in the submit page I put something like this:
    <jbo:Row id="myRow" datasource="ds" action="Update" rowkeyparam="MyRowKey" >
    <jbo:SetAttribute dataitem="*" />
    </jbo:Row>
    But how can I insert multiple rows like this:
    Id          Name
    1          ana
    2          monteiro
    3          maria
    Thanks!

    Hi Chris,
    I think this should give you what you need: Working with a Multiple Select List Item
    --Jennifer                                                                                                                                                                                                                                                                                                                                                                                                   

  • Inserting Multiple Rows into Database Table using JDBC Adapter - Efficiency

    I need to insert multiple rows into a database table using the JDBC adapter (receiver).
    I understand the traditional way of repeating the statement multiple times, each having its <access> element. However, I am just wondering whether this might be performance-inefficient, as it might insert records one by one.
    Is there a way to ensure that the records are inserted into the table as a block, rather than record-by-record?

    Hi Bhavesh/Kanwaljit,
    If we have multiple ACCESS tags then what happens is that the connection to the database is made only once. But the data is inserted row by row.
    Why i am saying this?
    If we add the following in JDBC Adapter..logSQLStatement = true. Then incase of multiple inserts we can see that there are multiple
    <i>Insert into tablename(EMP_NAME,EMP_ID) VALUES('J','1000')
    Insert into tablename(EMP_NAME,EMP_ID) VALUES('J','2000')</i>
    Doesnt this mean that rows are inserted one by one?
    Correct me if i am wrong.
    This does not mean that the transaction is not guaranted. Either all the rows will be inserted or rolled back.
    Regards,
    Sumit

  • Problem with inserting a chart into Powerpoint

    A box appears telling me that I must first close open dialog boxes but I have none open.  Next box says some charts cannot be combined with others and to choose a new chart type.   I have not selected another chart.  I have made plenty of charts in the past and never struck this before.

    Where can you find the defect number and description?
    Does it solve this issue in the release notes for 10.1.0.2.0 (10g)?
    * There is a limitation regarding the use of stream input for LOB
    types. Stream input for LOB types can only be used for 8.1.7 or
    later JDBC OCI driver connecting to an 8.1.7 or later Oracle
    server. The use of stream input for LOB types in all other
    configurations may result in data corruption. PreparedStatement
    stream input APIs include: setBinaryStream(), setAsciiStream(),
    setUnicodeStream(), setCharacterStream() and setObject().

  • Problem with updating UItable contents into Bapi Table

    Hi all,
         I am trying to send uitable contents as export parameters of a bapi, The values are not getting updated. Here is the code, please verify and let me the errors and solution if any.
      public java.lang.String Save( java.lang.String action )
        //@@begin Save()
            IPrivateConfig_Fields_View.IForm_ConfigElement ele;
              Zbapi_Config_Flds_Input input = new Zbapi_Config_Flds_Input();
              Zbapi_Form_Config tab = new Zbapi_Form_Config();
              String opt = wdContext.currentContextElement().getConfig_To_Option();
              int size = wdContext.nodeForm_Config().size();
              input.setForm_Type(opt);
              input.setForm_Act(action);
              tab = new Zbapi_Form_Config();
              for(int i=0;i<size;i++)
                   tab.setFld_Check(wdContext.nodeForm_Config().getElementAt(i).getAttributeAsText("Fld_Check"));
                   input.addForm_Config(tab);
              wdContext.nodeZbapi_Config_Flds_Input().bind(input);               
              try
                     wdContext.currentZbapi_Config_Flds_InputElement().modelObject().execute();
                catch(Exception ex)
                     ex.printStackTrace();
                wdContext.nodeOutput().invalidate();
                return wdContext.currentReturnElement().getMessage();
                //wdContext.nodeForm_Config().getElementAt(1).getAttributeAsText("Fld_Check");
        //@@end
    Thanks and regards
    Sai krishna
    Message was edited by: Konchada Sai Krishna

    Hi
    Try this
    IPrivateConfig_Fields_View.IForm_ConfigElement ele;
    Zbapi_Config_Flds_Input input = new Zbapi_Config_Flds_Input();
    //bind the node
    IPrivateConfig_Fields_View.nodeZbapi_Config_Flds_Input().bind(input);
    See this thread
    Re: Bapi_Transaction_Commit is not updating Values to R/3
    Kind Regards
    Mukesh

  • Problems in syncronyzing two threads into Test Stand using a Global Variable (TestStand 4.1.1)

    I have one thread that is doing TCPIP Aquisition into a Global variable defined in Teststand. And I have another thread that it supose to read it. All are in the same sequence and execution. The problem is that the aquisition thread got a lot of bytes, while the processing thread is reading always only a few. Do you know what the problem could be?
    I will attach also some pictures just to be maybe more clear...
    Attachments:
    Implementation_pictures.zip ‏368 KB

    I wasn't looking at your Sequence, I was looking at Receive_HDL_Block.JPG. What is that VI doing (the one with number 3 on the icon and Size_in_bytes as an input) ?
    Where in teststand are you doing any checking?
    I don't really understand your sequence.
    You have a sequence (running in a new thread) (why), following by another called Receiver Handler (also running in a new thread) then two more sequences which seem to do some with transmitting something (also running as new threads). You are only waiting on one of these threads (the Receiver Handler). There does seem to be any loops in TestStand, you dont seem to be bothered about the other threads that you have running. What happens when this test sequence finally does stop, what is stopping the Threads that you have running.
    Your pictures dont really seem to fit in with your Test Sequence, such as where does Test_005.vi fit into everything
    The whole thing is a bit of a nightmare.
    Maybe your best bet would be to scrap the lot and start again. Only this time have a better understanding of what you what to achieve, what would be best to put into Teststand and what to put into labview. Whether you really need all those new threads running.
    Sorry to be so blunt.
    Regards
    Ray Farmer
    Regards
    Ray Farmer

  • How do I insert  input data into anoracle table using C#

    Hi guys,
    I am new in the .NET arena and I am using Visual Studio 2005 Pro edition.. For instance I have 2 forms one being the main form which calls another to to insert captured text onto a form with the idea of passing it into the oracle database. I am failing to do that using C#. Where am I going wrong? Part of the code when I use actual values, data is written but when I want to write from input text from the form I get an Oracle message ORA-00936. A global connection is established in the first form.
    Here is the successful code:
    Try
    MyCmd.CommandText="insert into station (stn_abb,stn_no,stn_name)"+
    "values('MUT','0480','MUTARE')";
    Int rowsUpdated = MyCmd.ExecuteNonQuery();
    If (rowsUpdated == 0)
    MessageBox.Show("RECORD NOT WRITTEN");
    Else
    MessageBox.Show("RECORD WRITTEN TO TABLE");
    Txn.Commit();
    Here is the UNSUCCESSFUL code:
    Try
    MyCmd.CommandText = "insert into station (stn_abb,stn_no,stn_name)" +
    "values(@txtStnAbb.Text,@txtStnNo.Text,@txtName.Text)";
    Int rowsUpdated = MyCmd.ExecuteNonQuery();
    If (rowsUpdated == 0)
    MessageBox.Show("RECORD NOT WRITTEN");
    Else
    MessageBox.Show("RECORD WRITTEN TO TABLE");
    Txn.Commit();
    Regards,
    Ray.

    Hi,
    I assume that in the second example your intent is to use bind variables, but I dont see where you're actually binding any variables. Also, "@" is sqlserver syntax, Oracle's syntax is ":".
    Here's a complete example, hope it helps.
    Cheers
    Greg
    create table smallcol(col1 varchar2(5));
    using System;
    using System.Data;
    using Oracle.DataAccess.Client;
    using Oracle.DataAccess.Types;
    public class odpparams
         public static void Main()
              OracleConnection con = new OracleConnection("user id=scott;password=tiger;data source=orcl");
              con.Open();
              OracleCommand cmd = new OracleCommand("insert into testtab values(:1)",con);
    cmd.Parameters.Add(new OracleParameter("1",OracleDbType.Varchar2,4,"fred",ParameterDirection.Input));
    cmd.ExecuteNonQuery();
    Console.WriteLine("done, no errors");
    con.Dispose();
    }

  • Inserting multiple rows into a table using a multiple-select list

    I'm trying to figure out how to take the output of a multiple-select list (":" separated list of values) and use that to update a table by inserting multiple rows based on the values. Is there a straight-forward way to do that in APEX?
    Thanks.
    Chris

    Hi Chris,
    I think this should give you what you need: Working with a Multiple Select List Item
    --Jennifer                                                                                                                                                                                                                                                                                                                                                                                                   

  • Problems with INSERT  syntax ?

    Dear programmers,
    I am have a problem with INSERT Syntax,
    I have a table with 11 fields out of which one is auto_increment field(id), Now my problem is, Do i need to specifiy autoincrement field in INSERT statement. I dont thinks ?
    My Insert statement is as follows ,
    int result = st.executeUpdate("insert into tablename"
              +"(name, user_group, lage, preis, anmerkung, exp_uri, timestamp, nummer)"
              +"values +Objekt+"','"+Kategoriekey+"','"+Lage+"','"+Preis+"','"+Anmerkung+"','"+Dateiname+"','"+date.getTime()+"','"+ObjektID+"')");
    thanks in advance
    bye

    The answer to your question is maybe. Each database handles autoincrements differently. What database are you using?
    I also noticed that you are doing an insert using the standard Statement. You should look into using PreparedStatements for performance reasons and issues such as single quotes from within a string.
    Matt

  • Error inserting a row into a table with identity column using cfgrid on change

    I got an error on trying to insert a row into a table with identity column using cfgrid on change see below
    also i would like to use cfstoreproc instead of cfquery but which argument i need to pass and how to use it usually i use stored procedure
    update table (xxx,xxx,xxx)
    values (uu,uuu,uu)
         My component
    <!--- Edit a Media Type  --->
        <cffunction name="cfn_MediaType_Update" access="remote">
            <cfargument name="gridaction" type="string" required="yes">
            <cfargument name="gridrow" type="struct" required="yes">
            <cfargument name="gridchanged" type="struct" required="yes">
            <!--- Local variables --->
            <cfset var colname="">
            <cfset var value="">
            <!--- Process gridaction --->
            <cfswitch expression="#ARGUMENTS.gridaction#">
                <!--- Process updates --->
                <cfcase value="U">
                    <!--- Get column name and value --->
                    <cfset colname=StructKeyList(ARGUMENTS.gridchanged)>
                    <cfset value=ARGUMENTS.gridchanged[colname]>
                    <!--- Perform actual update --->
                    <cfquery datasource="#application.dsn#">
                    UPDATE SP.MediaType
                    SET #colname# = '#value#'
                    WHERE MediaTypeID = #ARGUMENTS.gridrow.MediaTypeID#
                    </cfquery>
                </cfcase>
                <!--- Process deletes --->
                <cfcase value="D">
                    <!--- Perform actual delete --->
                    <cfquery datasource="#application.dsn#">
                    update SP.MediaType
                    set Deleted=1
                    WHERE MediaTypeID = #ARGUMENTS.gridrow.MediaTypeID#
                    </cfquery>
                </cfcase>
                <cfcase value="I">
                    <!--- Get column name and value --->
                    <cfset colname=StructKeyList(ARGUMENTS.gridchanged)>
                    <cfset value=ARGUMENTS.gridchanged[colname]>
                    <!--- Perform actual update --->
                   <cfquery datasource="#application.dsn#">
                    insert into  SP.MediaType (#colname#)
                    Values ('#value#')              
                    </cfquery>
                </cfcase>
            </cfswitch>
        </cffunction>
    my table
    mediatype:
    mediatypeid primary key,identity
    mediatypename
    my code is
    <cfform method="post" name="GridExampleForm">
            <cfgrid format="html" name="grid_Tables2" pagesize="3"  selectmode="edit" width="800px" 
            delete="yes"
            insert="yes"
                  bind="cfc:sp3.testing.MediaType.cfn_MediaType_All
                                                                ({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})"
                  onchange="cfc:sp3.testing.MediaType.cfn_MediaType_Update({cfgridaction},
                                                {cfgridrow},
                                                {cfgridchanged})">
                <cfgridcolumn name="MediaTypeID" header="ID"  display="no"/>
                <cfgridcolumn name="MediaTypeName" header="Media Type" />
            </cfgrid>
    </cfform>
    on insert I get the following error message ajax logging error message
    http: Error invoking xxxxxxx/MediaType.cfc : Element '' is undefined in a CFML structure referenced as part of an expression.
    {"gridaction":"I","gridrow":{"MEDIATYPEID":"","MEDIATYPENAME":"uuuuuu","CFGRIDROWINDEX":4} ,"gridchanged":{}}
    Thanks

    Is this with the Travel database or another database?
    If it's another database then make sure your columns
    allow nulls. To check this in the Server Navigator, expand
    your DataSource down to the column.
    Select the column and view the Is Nullable property
    in the Property Sheet
    If still no luck, check out a tutorial, like Performing Inserts, ...
    http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/index.jsp
    John

  • Inserting data from one table into another table using PL/SQL

    HI,
    I am trying to insert values from one table into another using PL procedure, the values I want to retrieve from the table riverside1 are charac_id and charac_type and insert these values into another table called riverside2 , the stored procedure zorgs_gorfs(x,y) accepts two parameters which are 2 charac_id's of d characters in riverside1 then using insert statements inserts these characters from riverside1 into riverside2.
    CREATE OR REPLACE PROCEDURE zorgs_gorfs(x IN NUMBER, y IN NUMBER) AS
         BEGIN
              INSERT INTO riverside2
                   (charac_id)
              VALUES
                   (x);
    INSERT INTO riverside2
                   (charac_id)
              VALUES
                   (y);
          END zorgs_gorfs;
    /This works but the problem im having is that when I also try to insert the charac_type as well as the charac_id it doesnt work below is the code:
    CREATE OR REPLACE PROCEDURE zorgs_gorfs(x IN NUMBER, y IN NUMBER) AS
         BEGIN
              INSERT INTO riverside2
                   (charac_id,charac_tye)
              VALUES
                   (Select
                        charac_id,
                        charc_type
                   FROM
                        riverside1
                   WHERE
                        charac_id = x);
          END zorgs_gorfs;
    /can someone kindly sort me out

    modify this sql
    INSERT INTO riverside2
                   (charac_id,charac_tye)
              VALUES
                   (Select
                        charac_id,
                        charc_type
                   FROM
                        riverside1
                   WHERE
                        charac_id = x);as
    INSERT INTO riverside2
                   (charac_id,charac_tye)
              VALUES
                   (Select
                        charac_id,
                        charc_type
                   FROM
                        riverside1
                   WHERE
                        charac_id in ( x,y));But my suggestion would be consider revising your approach. It does not look that good.
    Thanks,
    karthick.

Maybe you are looking for

  • Videos Not evenGoing onto list

    Well I just bought my 30g ipod video and im all pumped about this video stuff. So i get home and i get my song's on and then try to get some movies that i have had on my computer for along time. But when i try to drag them to the iTunes music list th

  • PS CS5, Wacky Keyboard tool shortcuts

    Has anyone else had this, and been able to fix it?  My tool quick keys many times (and quite often) produce incorrect results! I have replicated this over and over, but, at random times. I keep getting the same incorrect tools too. I have been making

  • Good practice on passing GUI information to classes?

    I'm totally new to GUI programming suing java and swing components. So far I have onlu done GUI programming with old fashoned C-style approach. Anyway, I have a GUI built upon a tabbed pane, which holds alot of information. Every pane has components

  • How do I edit R3D footage from my Red One and Epic?

    Log and transfer is gone.  Native support not available.  It says 4K on the website, but it won't edit 4K in the real world.

  • Report on date parameters bipublisher 10g

    Hi, We have a report and we have date parameters to be passed to the report. We were able to generate it. Our requirement is, if we select dates then the report should be generated based on given dates. If we didnt select the dates, the report should