Jason Bennett's Developer Corner

 






Click to see the XML version of this web page.

>


View David Jason Bennett's profile on LinkedIn

 

 

A Little About Jason Bennett ...

I've had an interest in publishing technical articles and HELPFUL code for a few years.  I am (by trade and hobby) a developer who specializes in Oracle technologies and web based architectures.  I have been an employee of both TUSC and Oracle Corporation.  My intent here is to share my ideas and coding experiences with the developer community as a whole.  As with all developers some of my ideas are great and some of them are ....  well you know.  Anyway, I hope you find something here that will aid in your endeavor, or spark a new idea. 

I am more than happy to assist with technical issues and will even write a little code if need be. If you find something on the site that is really useful and you'd like to make a contribution (absolutely up to you and absolutely not required), just click the "Make a Donation" button on the left!

Good luck and good coding !




  Tuesday, March 08, 2005


Converting a String To a CLOB and Converting a CLOB to a String

The following code snippets demonstrate: (1) how to convert a Java String object to an Oracle CLOB object and (2) how to convert an Oracle CLOB object into a Java String object.  The code assumes you know how to define a JDBC connection and that you have imported the Oracle SQL types library.  I did not invent this method, but I did have a hard time finding an example that filled in all of the blanks.  Let me know if you have questions.  Here is the code:

   try
   {
      String v_clob_string = <STRING OF ANY LENGTH>;
  
      Connection conn = <define JDBC Connection>;
     
      CLOB v_clob = CLOB.createTemporary(conn,false,CLOB.DURATION_CALL);
      
      CallableStament cs = conn.prepareCall("begin ClobPackage.insertClob(?); end;");
 
      int x = v_clob.putString(1,p_clob_string);

      cs.setClob(1,v_clob);

      cs.execute();

      cs.close();

   }catch(Exception e){

        <Your exception handling code>

   }finally{

      <Might want to clean up connections here>

   }

 

   try
   {
   
      Connection conn = <define JDBC Connection>;
      
      CallableStament cs = conn.prepareCall("begin ? = ClobPackage.getClob; end;");
 
      cs.registerOutParameter(1,OracleTypes.CLOB);

      cs.execute();

       Clob  v_clob         = cs.getClob(1);
       long  v_len          = v_clob.length();
       String v_clob_string = v_clob.getSubString(1,(int)v_len);

       cs.close();

   }catch(Exception e){

        <Your exception handling code>

   }finally{

      <Might want to clean up connections here>

   }


5:07:24 PM    

Click here to visit the Radio UserLand website. © Copyright 2008Jason Bennett.
Last update: 8/28/2008; 9:47:57 PM.

March 2005
Sun Mon Tue Wed Thu Fri Sat
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Feb   May