title: Oracle PreparedStatement throws Value Too Large because of single quote escaping
body: <p>I seem to have a problem with a Java batch insert. What it does is inserting values with single quotes into an Oracle table.</p>
  
  <pre><code>java.sql.BatchUpdateException: ORA-12899: value too large for column "P40_001_CM"."PRODUCTDATA"."P_NAME" (actual: 76, maximum: 75)
  </code></pre>
  
  <p>The fact is that the value I need to insert as P_NAME is :</p>
  
  <pre><code>Best of Hollywood 2 Movie Collector's Pack: Todeszug nach Yuma / Recue Dawn
  </code></pre>
  
  <p>As you can see (or count if you like); this is exactly 75 characters in length, including the single quote. </p>
  
  <p>Code snippet I am using to handle single quotes :</p>
  
  <pre><code>case Types.VARCHAR:
  pstmt.setString(paramIndex, param.getValue().replace("'", "''"));
  break;
  </code></pre>
  
  <p>This approach works, and it does for most of my inserts, but in this particular case it will count the added single quote resulting the entire string to be 76 in length. And thus causes the exception.</p>
  
  <p>Thing is that when I run the insert statement in Squirrel, it just inserts without any problems. And it should, the actual value is still 75 long, only one quote was added to escape another.</p>
  
  <p>Somehow, the internally used OraclePreparedStatement does some kind of check (obviously not a very good one) on the length of the String that is passed and dismisses this before it can actually reach Oracle itself, or so it seems.</p>
  
  <p>How can I fix this ? I can't be the only one who ever ran into this behaviour ? </p>
  
  <p>Ah, btw, before anyone suggests, yes, I have tried :</p>
  
  <pre><code>`insert into GERMANSTUFF values('Best of Hollywood 2 Movie Collector'||chr(39)||'s Pack: Todeszug nach Zuma / Recue Dawn');`
  </code></pre>
  
  <p>and 
      <code>insert into GERMANSTUFF values(translate('Best of Hollywood 2 Movie Collector^s Pack: Todeszug nach Puma / Recue Dawn','^',chr(39)));</code>     </p>
  
  <p>and although this works in Squirrel as a direct SQL statement, it only made the String value on which the OraclePreparedStatement throws an error larger. Which seems logical I guess.</p>
  
  <p>I know I can replace the <code>'</code> by a <code>^</code> or just enlarge my destination column, but I don't consider these 'solutions' as the right way to solve this problem. Maybe it's something simple which I just haven't seen yet ?</p>