Updating a clob field
However, some database programs cannot run certain text operations on CLOB fields, such SQL commands with the "LIKE" condition.Therefore, it is often better to use other character data types for smaller text values.//RETRIEVING THE CLOB FROM ORACLE 8i Clob clob = Clob("XML"); Reader clob Stream = Character Stream(); String Buffer str Buffer = new String Buffer(); // Read from the Clob stream and write to the stringbuffer int nchars = 0; // Number of characters read char buffer = new char[10 * 1024]; // Buffer holding characters being transferred while( (nchars = clob Stream.read(buffer)) ! mglxxx, i got the code from rick working, what he posted in the very beginning.= -1 ) String str XML = str String(); //WRITING THE CLOB TO ORACLE 8i Statement statement2 = connect.create Statement(); mglxxx i am trying to update a CLOB in my table, but somehow i am not getting any luck. CLOB DB2 CODE THAT I USED FOR CLOB READ/WRITE READING FROM A CLOB FIELD Connection connect = null; Prepared Statement prep Statement = null; Result Set rs = null; String str XML = ""; String get Items Query = "SELECT IT_XML " "FROM " Database Names. "; connect = get Connection(); prep Statement = connect.prepare Statement(g(); if (rs ! I am so glad that the code is working fine, and so is updation of the Clob field with more than 4000 characters.The CLOB data type is similar to a BLOB, but includes character encoding, which defines a character set and the way each character is represented.BLOB data, on the other hand, consists of unformatted binary data.Common data types used for storing character data include char, varchar, and text.
Be careful, and specify WHERE clause to select only ONE record at the time, otherwise you will get an exception. I also can't see what you do to initialize BLOB column.
Before you do (e.g.): SELECT resume INTO dst_file FROM sam_emp WHERE ID = 1 FOR update; You MUST have that "resume" column with ID=1 set to either EMPTY_BLOB() or some other valid BLOB locator. Many things are different with BLOBs comparing to scalar types, and that's because it's an object. You do not use UPDATE, you must use locators, empty_blob() function, DBMS_LOB package, etc etc...
If the record does not exist, I would do the folloving: ----------------------- INSERT INTO sam_emp (id, resume) VALUES (sam_emp_seq.nextval, empty_blob()) RETURNING id INTO my_id; COMMIT; SELECT resume INTO dst_file FROM sam_emp WHERE ID = my_id FOR update; dbms_lob.fileopen(src_file, dbms_lob.file_readonly); lgh_file := dbms_lob.getlength(src_file); dbms_lob.loadfromfile(dst_file, src_file, lgh_file); COMMIT; dbms_lob.fileclose(src_file); ----------------------- So, I introduce a few more elements here - sam_emp_seq - sequencer to generate ID values for sam_- id - column in sam_emp table that will be used as the primary key - empty_blob() - built-in function to set valid empty BLOB locator - my_id - a variable to hold the value of ID generated by the sequencer in INSERT statement. LOADFROMFILE procedure is doing the update for you. If you code an application, you will have to use streams to deal with BLOBs, while with VARCHAR2 you won't.
Instead, the CLOB field serves as an address, which references the location of the data.
CLOBs provide a way to store unusually large amounts of text, such as an entire book or publication.