Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert string to oracle.sql.clob in java?

I'm coding a Java function inside Oracle Database which produce allot of text! how to convert a string to CLOB (oracle.sql.CLOB) in java? what is the straight-forward way to do?

I'm trying to build a function which has String as an input with oracle.sql.CLOB as an output, but it's not working! I'm not doing any jdbc related work!

here is what I have (which is not working!)

  public static CLOB str2clob(String s)
  {
         oracle.sql.CLOB clob = null;

         try
         {
               clob.setString(0,s);

         } catch (Exception e)
         {
         }
         return clob;
  }
like image 747
Data-Base Avatar asked Jul 14 '26 01:07

Data-Base


1 Answers

/*********************************************************************************************
 * From String to CLOB
 *  @return CLOB representation of string
 *********************************************************************************************/
private java.sql.Clob stringToClob(String source)
{
    try
    {
        return new javax.sql.rowset.serial.SerialClob(source.toCharArray());
    }
    catch (Exception e)
    {
        log.error("Could not convert string to a CLOB",e);
        return null;
    }
}
like image 152
Stan Sokolov Avatar answered Jul 15 '26 13:07

Stan Sokolov