Retrieving CLOB

Hello experts,
I am following the link:
https://forums.oracle.com/thread/725735
First, I am only trying to retrieve clob data (>32 k) from db to a Rich Text Editor field in apex app. I am not getting success for that field at all irrespective of how long is the text in db CLOB column. Using apex 4.0
I did three things:
1. added clob_get function in HTML Header and Body attribute of the page
2. added anonymous block as On Load-after header process . The code populates collection named CLOB_CONTENT from db CLOB column
3. added following code in Footer of the region which is holding Rich Text Editor item:
<script type="text/javascript">
<!--
addLoadEvent(clob_get);
//-->
</script>
But still the item does not get populated with any data. I feel either step3 is wrong ( I mean I may need to define addLoadEvent somewhere) or I am missing something else. Looks like clob_get function is not getting executed.
Please help.
Thanks,
RN

Might a plug-in be useful instead?
http://www.danielmcghan.us/2013/04/enkitec-clob-load-plug-in-for-apex-in.html
Scott

Similar Messages

  • HY000 error retrieving CLOB-data from oracle database via ODBC

    Hello,
    I get error HY000 [Oracle][ODBC][ORA] ORA-00932: inconsistent datatype when I want to show a CLOB column in my crystal report. The type of the field in the report is memo - in the database it is CLOB.
    How to retrieve CLOB-data from an Oracle 11GR2 database via ODBC in Crystal Report Version 12.3.0.601?
    Thanks in advance for any help.
    kind regards
    Monika Anna

    Hello,
    Who's ODBC driver are you using?
    Try our DataDirect drivers - https://smpdl.sap-ag.de/~sapidp/012002523100008666562008E/cr_datadirect53_win32.zip
    Thank you
    Don

  • Retrieving clob locator

    I am having trouble retrieving a clob locator from a column despite being able to set it in a previous statement. The clob is always returned as null.
    This happens to both an 8.1.6 and 8.1.7 with the latest classes12.zip
    Thanks,
    -elliott
    Here is my code snippet:
    oracle.sql.CLOB clob = null;
    // Select LOB locator into standard result set.
    StringBuffer sSelect = new StringBuffer();
    sSelect.append("SELECT " + mercColName + " FROM BUG" + whereClause.toString() + "FOR UPDATE");
    debug.println("Get Clob: " + sSelect.toString());
    ResultSet rs =
    stmt.executeQuery(sSelect.toString());
    while (rs.next()) {
    // Get LOB locator into Java wrapper classes.
    try {
    clob = (oracle.sql.CLOB) rs.getClob(1);
    catch (Exception ex) {
    //do nothing
    if (clob == null)
    //update row
    StringBuffer sUpdateClob = new StringBuffer();
    sUpdateClob.append("UPDATE BUG SET " + mercColName + " = (empty_clob()) " + whereClause.toString());
    debug.println("Update Clob: " + sUpdateClob.toString());
    stmt.execute(sUpdateClob.toString());
    m_DelayConnection.commit();
    ResultSet rs2 =
    stmt.executeQuery(sSelect.toString());
    while (rs2.next()) {
    // Get LOB locator into Java wrapper classes.
    clob = (oracle.sql.CLOB) rs2.getObject(1);
    java.io.Writer writer;
    // read data into a character array
    char[] data = pval.toCharArray();
    // write the array of character data to a CLOB
    writer = clob.getCharacterOutputStream();

    Found the problem. I was using the ODBC driver instead of the JDBC driver.

  • How to store and retrieve clob data fields

    Hai al l,
    How to sotre resumes of a Jobseekers in Oracle Data Base.Which version is enough(8i or 9i) and CLOB or BLOB is Preferable.
    Now my requirement is to insert the all the Attachments into Oracle database. I have little bit knowledge on inserting image file into DB. Now I want to insert More than 1000000 resume Attachments (all are .doc or .rtf files).Can you suggest me on this with a sample program .I am really thankful to all of our Members support and Valuable doubt clarifications.
    I am waiting for your valueble reply
    thanks in advance
    Kanchnaa
    I am really thankful for your support and Valuable doubt clarifications.

    CLOBs and BLOBs are physically stored just like any other Oracle data type, in the data files that make up the database, the .dbf files. They're not stored as seperate files that you can use outside of Oracle.
    Oracle has a seperate special data type for binary objects stored outside the database, the BFILE data type. However, this type is read-only from a database connection (and therefore from JDBC); the files have to be placed on the Oracle server some other way and the BFILE object is created as a pointer to that external resource. I think built-in stored procedures are used to actually read the data from the binary object.
    I've never used this datatype and can't tell you much more about it. See the documentation:
    http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14200/sql_elements001.htm#sthref175

  • Error retrieving Clob

    Here's my code:
    Statement stmt= conn.createStatement();
    String sql= "select clob from table";
    ResultSet rs= stmt.executeQuery(sql);
    while (rs.next()) {
    Clob clob= ((ResultSet)rs).getClob("clob");
    String tmpClob= clob.getSubString(1, 1500);
    System.out.println(tmpClob);
    I get the following error:
    java.lang.AbstractMethodError: oracle/jdbc/driver/OracleResultSet.getClob
    Any ideas?

    coreect like the follwing:
    Clob clob= ((ResultSet)rs).getClob(1);
    // 1 is the column index of clob data in the table
    // In "select clob from table", 'table' is the name of the table? if not
    // provide the appropriate table..

  • Unable to retrieve CLOB data from oracle

    hello I am trying to retreive a clob data from database. I am passing "country" to get "information". after submitting data it is showing SQLException caught: General error .
    whatz wrong.? can anybody help?
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    public class ClobTest2 extends HttpServlet{
         public void doGet( HttpServletRequest req, HttpServletResponse res )
              throws ServletException, IOException
                   Connection conn = null;
                   Statement st = null;
                   ResultSet rs = null;
                   res.setContentType( "text/html" );
                   PrintWriter out = res.getWriter();
                   String coun$ = "";
                   coun$ = req.getParameter( "coun" );
                   try{
                      Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver");
                      conn = DriverManager.getConnection( "jdbc:odbc:clobtester",    "temp", "sol" );
                      st = conn.createStatement();
                      rs = st.executeQuery( "SELECT information FROM testclob WHERE country = '"+coun$+"' ");
                        while( rs.next() )
                         out.println(rs.getClob(1) );
                      catch( ClassNotFoundException e )
                           out.println( "Could not load database driver" + e.getMessage() );
                      catch( SQLException e )
                           out.println("SQLException caught: " + e.getMessage()  );
                    e.printStackTrace();
                   catch( Exception e )
                       System.err.println( "Problem closing the database" );
                 try{
                             st.close();
                             conn.close();
                         }catch( Exception e )
                            System.err.println( "Problem closing the database" );
         }

    certainly but this problem can go on several
    category. and I am the needy one to get the solutionHowever I don't need to answer cross-posted questions. And I don't.

  • Error when retrieving oracle clobs

    Here's the sql statement that we are running:
    SELECT dbms_lob.substr(sql_statement,dbms_lob.getlength(sql_statement),1) sql_statement FROM query
    WHERE query_tk = [Param.1]
    If the sql_statement is > 4000 chars, we are getting this error:
    Fatal Error
    A SQL Error has occurred on query, ORA-06502: PL/SQL: numeric or value error: character string buffer too small ORA-06512: at line 1 .

    We are seeing this outside of xmii as well. 
    Here's the background.  We originally tried to do a normal insert to the clob (thru xmii) but we got errors when inserting values of more than 4000 chars.  So, we inserted the clob differently (code used below).  That's when we started getting this new error.  Is there another way to insert/retrieve clobs?
       --INSERT "base" row if it does not already exist.
       BEGIN
         SELECT  query_tk
           INTO  v_dummy
           FROM  query
           WHERE query_tk = p_query_tk;
         EXCEPTION
           WHEN NO_DATA_FOUND THEN
             INSERT INTO query
               (query_tk
               ,last_updated_timestamp
               ,sql_statement
             VALUES
               (p_query_tk
               ,SYSDATE
               ,'DUMMY');
       END;
       --Initialize buffer with data to be inserted
       v_copy_length := LENGTH(p_sql_statement);
       -- get LOB handle
       SELECT  sql_statement
         INTO  v_lobloc
         FROM  query
         WHERE query_tk = p_query_tk
         FOR UPDATE;
       dbms_lob.write(v_lobloc,v_copy_length,1,p_sql_statement);

  • Problems saving Unicode in an Oracle CLOB

    We found a problem with saving Unicode in an Oracle CLOB. We use thin
    drivers and Oracle 9.2.0.3.0 The character set of the database is UTF8.
    The following code works:
    // Retrieve clob object into ResultSet rs
    // Data to be saved is in String str
    // Save data:
    oracle.sql.CLOB theClob = (oracle.sql.CLOB)rs.getObject(1);
    theClob.putString(1, str);
    But the following code does not save the data properly while this is
    usually recommended in code samples:
    oracle.sql.CLOB theClob = (oracle.sql.CLOB)rs.getObject(1);
    Writer out = theClob.getCharacterOutputStream();
    out.write( str.toCharArray() );
    out.flush();
    out.close();
    What could be the reasons why the second approach is failing?
    Regards,
    Joop Kaashoek

    Thanks for your reply.
    When I insert .gif files JDeveloper ends with a message saying "Process exited with exit code 0". I then go and check in the database and I find the image added to the table.
    With a word doc, JDeveloper does not give that message. No message at all regarding what the status of the process is. And the document is not added to the database. No error messages too. Could this be an issue with Oracle?

  • XSQL and Clobs

    I have run into some trouble with retrieving Clob fields with XSQL, seems as though the resultset I am getting is a pointer to the data and not the data itself.
    This is what I am trying to do.
    1. Query an Oracle 8i data base that contains multiple clob fields in which the data has been Base64 encoded (using ColdFusion).
    2. Loop over the Query for the designated Clob fields and decode them using BASE64Decoder() from the sun.misc library.
    3. Create a new XML node with the decoded clob value (which would be a WDDX structure).
    I have used the <xsql:query > and that returns the clob field (still base64 encoded) just fine. Should I change my thinking and look for the XML node and Decode that value and create a new node from that. ????
    Hear is a copy of my code. Any Help would be appreciated.
    // Copyright (c) 2000 prosavvy
    package xsql.myclasses;
    * A Class class.
    * <P>
    * @author gwilliams
    import oracle.xml.xsql.*;
    import org.w3c.dom.*;
    import java.sql.*;
    import java.lang.String;
    import java.lang.Object.*;
    import oracle.sql.*;
    import oracle.jdbc.driver.OracleResultSet;
    import java.io.*;
    import sun.misc.BASE64Decoder;
    public class decodetest extends XSQLActionHandlerImpl {
    public void handleAction( Node rootNode ) throws SQLException {
    ResultSet rs = null;
    Statement s = null;
    String stmt = "select sessiondata from persons where personid = 169158";
    if (!requiredConnectionProvided(rootNode)) {
    return;
    try {
    s = getPageRequest().getJDBCConnection().createStatement();
    rs = s.executeQuery(stmt);
    String curDate="";
    String wddx = new String();
    if (rs.next()) {
    // System.out.println(rs.getClob(1));
    curDate = rs.getClob(1).toString();
    BASE64Decoder decoder = new BASE64Decoder();
    wddx = new String(decoder.decodeBuffer(curDate));
    System.out.println(wddx);
    addResultElement(rootNode,"Date",wddx);
    rs.close();
    s.close();
    catch (IOException exs) {
    this.reportErrorIncludingStatement(rootNode,stmt,exs.getMessage());
    rs.close();
    s.close();
    null

    Greg. Your suspicion is correct. The CLOB is just a CLOB "locator" that you select. You need to call the getCharacterStream method to retrieve the stream of contents.
    Here's a modified version of your action handler that appears to work for me.
    import oracle.xml.xsql.*;
    import org.w3c.dom.*;
    import java.sql.*;
    import java.lang.String;
    import java.lang.Object.*;
    import oracle.sql.*;
    import oracle.jdbc.driver.OracleResultSet;
    import java.io.*;
    import sun.misc.BASE64Decoder;
    public class DecodeCLOB extends XSQLActionHandlerImpl {
    public void handleAction( Node rootNode ) throws SQLException {
    ResultSet rs = null;
    Statement s = null;
    String stmt = "select sessiondata from persons where personid = 1";
    if (!requiredConnectionProvided(rootNode)) {
    return;
    try {
    s = getPageRequest().getJDBCConnection().createStatement();
    rs = s.executeQuery(stmt);
    String curDate="";
    String wddx = new String();
    if (rs.next()) {
    // System.out.println(rs.getClob(1));
    Reader r = rs.getClob(1).getCharacterStream();
    StringBuffer sb = new StringBuffer();
    char[] buf = new char[256];
    int charsRead = -1;
    while ( (charsRead = r.read(buf)) != -1 ) {
    sb.append(buf,0,charsRead);
    curDate = sb.toString();
    BASE64Decoder decoder = new BASE64Decoder();
    wddx = new String(decoder.decodeBuffer(curDate));
    System.out.println(wddx);
    addResultElement(rootNode,"Date",wddx);
    rs.close();
    s.close();
    catch (IOException exs) {
    reportErrorIncludingStatement(rootNode,stmt,exs.getMessage());
    rs.close();
    s.close();
    }

  • Insert CLOB into oracle under weblogic

    Situation: running my servlet under weblogic, want to insert more than 4000 characters into CLOB of oracle 8.1.7
    Problem: cannot be done by using code which is able to do it under tomcat
    i use this code in tomcat:
    import java.sql.*;
    import oracle.sql.CLOB;
    import oracle.jdbc.driver.OracleResultSet;
    con.setAutoCommit(false);
    Statement stmt = con.createStatement();
    rs = stmt.executeQuery("SELECT clob_field FROM table where rid=id FOR UPDATE");
    rs.next();
    CLOB clob = ((OracleResultSet)rs).getCLOB(1);
    Writer writer = clob.getCharacterOutputStream();
    writer.write(dataString);
    writer.close()l
    con.commit();
    con.setAutoCommit(true);
    stmt.close();
    after that i know that i can't use API of oracle when i'm using weblogic (e.g. oracle.sql.CLOB)
    and i find this code from other user:
    import weblogic.jdbc.vendor.oracle.OracleThinClob;
    import java.io.*;
    import java.sql.*;
    PreparedStatement stmt = con.prepareStatement ( "INSERT INTO database VALUES ( ?, EMPTY_CLOB() )" );
    stmt.setInt ( 1, 1 );
    // inserts a new entry with an empty clob object
    stmt.executeUpdate ();
    if ( stmt != null )
    stmt.close();
    // retrieves CLOB-Object
    stmt = con.prepareStatement ( "SELECT clob_field FROM database WHERE id=?" );
    stmt.setInt ( 1, 1 );
    ResultSet rs = stmt.executeQuery ( );
    if ( rs.next() )
    Clob cl = rs.getClob(1);
    Writer clobWriter = ((OracleThinClob)cl).getCharacterOutputStream();
    // Open the sample file as a stream for insertion into the Clob column
    File testFile = new File ( "file.txt" );
    FileReader testReader = new FileReader ( testFile );
    // buffer to hold data to being written to the clob.
    char[] cBuffer = new char[((OracleThinClob)cl).getBufferSize()];
    // Read data from file, write it to clob
    int iRead = 0;
    while( (iRead= testReader.read(cBuffer)) != -1 )
    clobWriter.write( cBuffer, 0, iRead);
    testReader.close();
    clobWriter.close();
    if ( rs != null )
    rs.close();
    if ( stmt != null )
    stmt.close();
    // update clob-data in database
    stmt = con.prepareStatement ( "UPDATE database SET clob_field = ? WHERE id = ?" );
    stmt.setClob ( 1, cl );
    stmt.setInt ( 2, 1 );
    stmt.executeUpdate();
    it throws java.lang.ClassCastException: oracle.sql.CLOB
    but i haven't imported or used any API from oracle.........
    please help
    thanks

    hi,
    unfortunatly, you can't do this with welbogic6.1 because it 'manage' itself oracle librairies (weblogic.jar),
    here is the way i solved the pb for BLOB :
    i replaced :
    BLOB blob = ((OracleResultSet)rs).getBLOB(1);
    by
    weblogic.jdbc.rmi.SerialOracleBlob cast1 =(weblogic.jdbc.rmi.SerialOracleBlob)rs.getBlob("myBlob");
    weblogic.jdbc.rmi.internal.OracleTBlobImpl cast2 =(weblogic.jdbc.rmi.internal.OracleTBlobImpl)cast1.getTheRealBlob();
    BLOB myBlob = (oracle.sql.BLOB)cast2.getTheRealBlob();
    it is the same for clob (i suppose ^_^)
    hope this helps !
    Badr.

  • Oracle JDBC (10g) reading clobs -- best practices

    What is the better approach using oracle 10g to save clobs:
    #1) This:
    PreparedStatement pstmt = conn.prepareStatement
    //Create the clob for insert
    Clobs Clobs = new Clobs();
    CLOB TempClob = Clobs.CreateTemporaryCachedCLOB(conn);
    java.io.Writer writer = TempClob.getCharacterOutputStream();
    writer.write(Description);
    writer.flush();
    writer.close();
    #2) Or this:
    OraclePreparedStatement pstmt = (OraclePreparedStatement)conn.prepareStatement
    pstmt.setStringForClob()
    According to my notes, it is #2.
    What is the better approach to read clobs:
    #1) Stream the clob
    //Get character stream to retrieve clob data
    Reader instream = ClobIn.getCharacterStream();
    //Create temporary buffer for read
    char[] buffer = new char[10];
    //Length of characters read
    int length = 0;
    //Fetch data
    while ((length = instream.read(buffer)) != -1){
    for (int i=0; i<length; i++){
    Contents += buffer;
    //Close input stream
    instream.close();
    //Empty LOB
    ClobIn.empty_lob();
    #2) Or this:
    Simply use rs.getString() to get your clob contents. This will return the entire clob and will not truncate.
    Im just confused on the best practices for performance/memory allocation and I keep reading people saying different.
    Reposted in JDBC forum

    Check chapter 16 of "PL/SQL Programming", by Oracle Press, for a starter.
    Then have a look at this link - I found it helpful: http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/files/advanced/LOBSample/LOBSample.java.html

  • Doubt handling Clob columns with Java JDBC api

    Hi,
    we have a doubt handling Clob columns with Java JDBC api.
    Reading Oracle 10g official documentation (document b10979.pdf, page 236), we found this note:
    ============================================
    To write LOB data, the application must acquire a write lock on the LOB object. One way to accomplish this is through a SELECT FOR UPDATE. Also, disable auto-commit mode.
    ============================================
    We also found a java sample code about how to handle Lob objects at this URL:
    http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/files/advanced/LOBSample/LOBSample.java.html
    In our java2 application, we access Clob objects in a quite different
    manner: we use normal setString() and getString() methods, as described into paragraph "Shortcuts For Inserting and Retrieving CLOB Data"
    (document b10979.pdf, page 244).
    Using those methods, we never lock the table row by a SELECT FOR UPDATE statement (as described into the note above). We use simply SELECT, UPDATE and INSERT prepared statement.
    In this way we can insert both clob objects and normal timestamp, number and other types with a single insert statement. Idem for update.
    To recap, our question is:
    Is it mandatory to create a SELECT FOR UPDATE statement when updating clob data? What may be the consequences if we don't use it? It is also correct to insert with a single sql statement both clob and not clob data using the setString() method for the clob types? And more than one lob column in the same record?
    bye,
    luca acri.

    And columns of type FLOAT. These also have, for some unknown reason a metadata type of OTHER, and a type string of 'FLOAT'. Yet PreparedStatement.setNull(x, Types.OTHER) doesn't work and setNull(x, Types.DECIMAL) does.

  • JSP and CLOB's

    Has anyone got CLOB data from a column to a JSP page?
    I have tried many options and seem to always get the 'stream closed' errror.
    Clob outClob = ((OracleResultSet)reset.getClob("column_name");
    I tried a Reader etc. No luck.
    I am using Tomcat, and oracle 8.1.6
    mark =.= [email protected]

    Hi Mark,
    try this code:
    public void dumpClob (JspWriter out, CLOB clob) throws Exception {
    // get character stream to retrieve clob data
    InputStream instream = clob.getAsciiStream();
    // create temporary buffer for read
    byte[] buffer = new byte[10];
    // length of characters read
    int length = 0;
    // fetch data
    while ((length = instream.read(buffer)) != -1) {
                   for (int i=0; i < length; i++) {
         if (buffer[i] == 13 || buffer[i] == 12) {
         // out.print("<BR>");
                             out.print((char)buffer);
         else {
         out.print((char)buffer[i]);
    out.flush();
    instream.close();
    And in the jsp:
    <%
    dumpClob(out,(oracle.sql.CLOB )rs.getObject("field"));
    %>
    I hope this helps you!
    Regards,
    JCarlos
    [email protected]

  • Nice solution to change a lot of procedures at once.

    if you have to do little changes in a lot of your Procedures / Functions or Packages here is a nice solution to do this in a very short time:
    CREATE TABLE T_SOURCE
    SOURCE_ID NUMBER,
    NAME VARCHAR2(30 BYTE),
    SOURCETEXT CLOB
    CREATE OR REPLACE PROCEDURE CIAS_PUFFER.pr_t_source
    IS
    NAME: pr_t_source
    $Archive: //PVCS/archives/10gh/PR_T_SOURCE.prc_v $
    $Author: ext0523 $
    $Date: Aug 04 2008 17:26:54 $
    $Revision: 1.2 $
    CURSOR c_all_obj
    IS
    SELECT object_name
    FROM all_objects
    WHERE owner <>'SYS'
    AND object_type = 'PROCEDURE'
    ORDER BY object_name;
    CURSOR c_prog (cp_name VARCHAR2)
    IS
    SELECT *
    FROM all_source
    WHERE NAME = cp_name
    ORDER BY line;
    v_replace VARCHAR2 (999);
    v_st CLOB;
    i PLS_INTEGER := 0;
    BEGIN
    EXECUTE IMMEDIATE ('truncate table t_source');
    FOR rec_all_obj IN c_all_obj
    LOOP
    i := i + 1;
    v_st := '--$ARCHIVE$'||chr(10)||'--$AUTHOR$'||chr(10)||'--$DATE$'
    ||chr(10)||'--$REVISION$'||chr(10)||chr(10);
    v_st := v_st||'CREATE OR REPLACE ';
    FOR rec_prog IN c_prog (rec_all_obj.object_name)
    LOOP
    v_replace := UPPER (rec_prog.text);
    if instr(v_replace,'$ARCHIVE') >0 then v_replace :=''; end if;
    if instr(v_replace,'$AUTHOR') >0 then v_replace :=''; end if;
    if instr(v_replace,'$DATE') >0 then v_replace :=''; end if;
    if instr(v_replace,'$REVISION') >0 then v_replace :=''; end if;
    v_replace :=
    REPLACE (v_replace,
    '[email protected]',
    'prot_easy_cias'
    v_replace :=
    REPLACE (v_replace, '[email protected]', 'easy2cias');
    v_st := v_st || v_replace;
    END LOOP;
    INSERT INTO t_source
    VALUES (i, rec_all_obj.object_name, v_st);
    END LOOP;
    COMMIT;
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    NULL;
    WHEN OTHERS
    THEN
    -- Consider logging the error and then re-raise
    RAISE;
    END pr_t_source;
    // classpath= /ORACLE/u01/app/oracle/product/10.2.0.3/jdbc/lib/ojdbc14.jar
    // Java SQL classes
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.Statement;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    // Oracle JDBC driver class
    import oracle.jdbc.OracleDriver;
    // Java IO classes
    import java.io.IOException;
    import java.io.BufferedReader;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    //Java Util classes
    import java.util.Properties;
    * This class demonstrates the Oracle JDBC 10g enhanced features for inserting
    * and retrieving CLOB data from the database. Using the new features, large
    * data of more than 32765 bytes can be inserted into the database using the
    * existing PreparedStatement.setString() and PreparedStatement.getString()
    * methods.
    public class ClobMan {
    /* Database Connection object */
    private Connection conn = null;
    /* Variables to hold database details */
    private String url = null;
    private String user = null;
    private String password = null;
    // Create a property object to hold the username, password and
    // the new property SetBigStringTryClob.
    private Properties props = new Properties();
    /* String to hold file name */
    private String fileName = null;
    * Default Constructor to instantiate and get a handle to class methods
    * and variables.
    public ClobMan(String fileName) {
    this.fileName = fileName;
    * Main runnable class.
    public static void main(String[] args) throws SQLException {
    // Instantiate the main class.
    ClobMan clobMan = new ClobMan(args[0]);
    // Load the Oracle JDBC driver class.
    DriverManager.registerDriver(new OracleDriver());
    // Load the database details into the variables.
    String dbUrl = "jdbc:oracle:thin:@pmol:1550:dbpmol";
    clobMan.url = dbUrl;
    clobMan.user = "gh10";
    clobMan.password = "secret";
    // Populate the property object to hold the username, password and
    // the new property 'SetBigStringTryClob' which is set to true. Setting
    // this property allows inserting of large data using the existing
    // setString() method, to a CLOB column in the database.
    clobMan.props.put("user", clobMan.user );
    clobMan.props.put("password", clobMan.password);
    clobMan.props.put("SetBigStringTryClob", "true");
    // Check if the table 'CLOB_TAB' is present in the database.
    //clobMan.checkTables();
    // Call the methods to insert and select CLOB from the database.
    //clobMan.insertClob();
    clobMan.selectClob();
    * This method will insert the data into a CLOB column in the database.
    * Oracle JDBC 10g has enhanced the existing PreparedStatement.setString()
    * method for setting the data more than 32765 bytes. So, using setString(),
    * it is now easy to insert CLOB data into the database directly.
    private void insertClob() throws SQLException {
    // Create a PreparedStatement object.
    PreparedStatement pstmt = null;
    try {
    // Create the database connection, if it is closed.
    if ((conn==null)||conn.isClosed()){
    // Connect to the database.
    conn = DriverManager.getConnection( this.url, this.props );
    // Create SQL query to insert data into the CLOB column in the database.
    String sql = "INSERT INTO clob_tab VALUES(?)";
    // Read a big file(larger than 32765 bytes)
    String str = this.readFile();
    // Create the OraclePreparedStatement object
    pstmt = conn.prepareStatement(sql);
    // Use the same setString() method which is enhanced to insert
    // the CLOB data. The string data is automatically transformed into a
    // clob and inserted into the database column. Make sure that the
    // Connection property - 'SetBigStringTryClob' is set to true for
    // the insert to happen.
    pstmt.setString(1,str);
    // Execute the PreparedStatement
    pstmt.executeUpdate();
    } catch (SQLException sqlex) {
    // Catch Exceptions and display messages accordingly.
    System.out.println("SQLException while connecting and inserting into " +
    "the database table: " + sqlex.toString());
    } catch (Exception ex) {
    System.out.println("Exception while connecting and inserting into the" +
    " database table: " + ex.toString());
    } finally {
    // Close the Statement and the connection objects.
    if (pstmt!=null) pstmt.close();
    if (conn!=null) conn.close();
    * This method reads the CLOB data from the database by using getString()
    * method.
    private void selectClob() throws SQLException {
    // Create a PreparedStatement object
    PreparedStatement pstmt = null;
    // Create a ResultSet to hold the records retrieved.
    ResultSet rset = null;
    try {
    // Create the database connection, if it is closed.
    if ((conn==null)||conn.isClosed()){
    // Connect to the database.
    conn = DriverManager.getConnection( this.url, this.props );
    // Create SQL query statement to retrieve records having CLOB data from
    // the database.
    String sqlCall = "SELECT rownum, name, sourcetext FROM t_source";
    pstmt= conn.prepareStatement(sqlCall);
    // Execute the PrepareStatement
    rset = pstmt.executeQuery();
    String rownum = null;
    String o_name =null;
    String clobVal = null;
    // Get the CLOB value from the resultset
    //java.io.BufferedWriter out = new java.io.BufferedWriter(new java.io.FileWriter("pr_all.sql"));
    while (rset.next()) {
    rownum = rset.getString(1);
         o_name = rset.getString(2);
         clobVal = rset.getString(3);
    System.out.println(" length: "+clobVal.length()+" "+o_name+" "+rownum);
         java.io.BufferedWriter out =
         new java.io.BufferedWriter(new java.io.FileWriter(o_name+".prc"));
         out.write(clobVal);
         out.newLine();
         out.write("/");
         out.newLine();
         out.newLine();
    out.flush();
    out.close();
    } catch (SQLException sqlex) {
    // Catch Exceptions and display messages accordingly.
    System.out.println("SQLException while connecting and querying the " +
    "database table: " + sqlex.toString());
    } catch (Exception ex) {
    System.out.println("Exception while connecting and querying the " +
    "database table: " + ex.toString());
    } finally {
    // Close the resultset, statement and the connection objects.
    if (rset !=null) rset.close();
    if (pstmt!=null) pstmt.close();
    if (conn!=null) conn.close();
    * Method to check if the table ('CLOB_TAB') exists in the database; if not
    * then it is created.
    * Table Name: CLOB_TAB
    * Column Name Type
    * col_col CLOB
    private void checkTables() {
    Statement stmt = null;
    ResultSet rset = null;
    try {
    // Create the database connection, if it is closed.
    if ((conn==null)||conn.isClosed()){
    // Connect to the database.
    conn = DriverManager.getConnection( this.url, this.props );
    // Create Statement object
    stmt = conn.createStatement();
    // Check if the table is present
    rset = stmt.executeQuery(" SELECT table_name FROM user_tables "+
    " WHERE table_name = 'CLOB_TAB' ");
    // If the table is not present, then create the table.
    if (!rset.next()) {
    // Table does not exist, create it
    stmt.executeUpdate(" CREATE TABLE clob_tab(clob_col CLOB)");
    } catch (SQLException sqlEx) {
    System.out.println("Could not create table clob_tab : "
    +sqlEx.toString());
    } finally {
    try {
    if( rset != null ) rset.close();
    if( stmt != null ) stmt.close();
    if (conn!=null) conn.close();
    } catch(SQLException ex) {
    System.out.println("Could not close objects in checkTables method : "
    +ex.toString());
    * This method reads the specified text file and, returns the content
    * as a string.
    private String readFile()
    throws FileNotFoundException, IOException{
    // Read the file whose content has to be passed as String
    BufferedReader br = new BufferedReader(new FileReader(fileName));
    String nextLine = "";
    StringBuffer sb = new StringBuffer();
    while ((nextLine = br.readLine()) != null) {
    sb.append(nextLine);
    // Convert the content into to a string
    String clobData = sb.toString();
    // Return the data.
    return clobData;
    sqlplus -s @pr_all.sql;

    Is there a better way to satisfy such claim?I have to say I would not consider doing this in the database. Source control would allow you to manage (review / commit, not to mention revert) the results of such a potentially dangerours global search and replace.
    Such as if it UPPERcased all my source code for example.
    v_replace := UPPER (rec_prog.text);

  • XML string to XML parsing in JCD

    I have stored an XML file as a CLOB in the Oracle DB. While fetching this data into JCD using Oracle OTD, I am getting this CLOB field as a string containing the XML. Now I want to parse this XML string to XML, as I need to map the individual fields to an XSD OTD, which will be my output.
    Kindly suggest a way to achieve this.

    An XSD OTD has an unmarshalFromString() method:
    inputFormat.unmarshalFromString( strData );
    When putting the XML into the CLOB it could be a good idea to wrap an outputstream into a Writer object in order to make certain that the encoding is correct, depending how the data is represented. When retrieving CLOB data using getCharacterStream() you will get a Reader object where the encoding is already given.

Maybe you are looking for

  • Zen Micro:The Full Story - Working ? Broken ? Happy or Sa

    <SPAN>Ok i realise that there are a lot of people having problems with their Micro's so lets see how this all equates shall we ? I suggest we : <SPAN>. How many Micros have you had so far?<B><SPAN></B> <SPAN>2. Are you happy with your current Zen Mic

  • 1st Generation iMac G5 with new main logic board but now no Bluetooth?

    Greetings: As an owner of a 1st generation iMac, I can finally report that my iMacG G5 is now working fine since the main logic board has been replaced because of bad capacitors. A NEW problem has been created. My internal bluetooth no longer works a

  • Do you have any idea about EPC error? If yes,  Please come in.

    Hellow : please try to solve the EPC-INIT failed epc-95 error which arbitrarily raises any day, we can not say that it raises only during peak time.It comes arbitrarily any time any day. Initially it was use to come after every 5 to 10 days But now i

  • Mavericks and Airplay issues

    I just installed new updates for Mavericks, not the OS itself, just the automatic updates. Now my airplay won't mirror from my computer. It will not allow me to change from "extend desktop" to "mirror". I am getting sound on my TV from whatever I am

  • Table of contents missbehaving

    Hello, I always seem to encounter the same problem when setting-up the TOC of multi chapter books. When I generate my TOC, the Heading 2 (flow A) title which is at the top of the page, always ends up placed after my Sideheads (flow B) which are lower