title: Create CLOB from long string using JDBC
body: <p>I have the following query:</p>
  
  <pre><code>select id from table1 where some_func(?) = 1;
  </code></pre>
  
  <p>where <code>some_func</code> is a function which allows its arguments to be either VARCHAR2 or CLOB, and <code>?</code> is some string, which could be really long.</p>
  
  <p>I am trying to use the following code to bind variables:</p>
  
  <pre><code>stmt.setObject(i+1, obj);
  </code></pre>
  
  <p>but in case of <code>string.length()</code> > 4000 I get the following error:</p>
  
  <pre><code>java.sql.SQLException: ORA-01460: unimplemented or unreasonable conversion requested
  </code></pre>
  
  <p>for an obvious reason: the VARCHAR2 size limit is 4000 characters. </p>
  
  <p>I then tried to use the following code:</p>
  
  <pre><code>if(obj instanceof String &amp;&amp; ((String) obj).length() &gt;= 4000) {
    String s = (String) obj;
    StringReader stringReader = new StringReader(s);
    stmt.setClob(i+1, stringReader, s.length());
  } else {
    stmt.setObject(i+1, obj);
  }
  </code></pre>
  
  <p>which gave a different error:</p>
  
  <pre><code>ORA-22922: nonexistent LOB value
  </code></pre>
  
  <p>The last idea I tried was to create a CLOB using <code>oracle.sql.CLOB.createTemporary()</code> method but it failed because of the following exception:</p>
  
  <pre><code>java.lang.ClassCastException:
    org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper 
    cannot be cast to oracle.jdbc.OracleConnection
  </code></pre>
  
  <p>What am I doing wrong? Are there any other possibilities to do this?</p>