title: DB2 SQLCODE:-302 SQLSTATE:22001 when inserting rows with replacing new line characters
body: <p>I'm faced with a problem that is an error occurred by trying to insert rows with replacing new line characters. </p>
  
  <p><strong>The environment</strong>: </p>
  
  <p>OS: AIX 7<br>
  DBMS: DB2<br>
  Version of JDBC driver: db2jcc4-10.5.4<br>
  Encoding: UTF-8 (DBMS and application)</p>
  
  <p><strong>The problem</strong>:</p>
  
  <p>I have a table, "TBA" and it has a column, "CONTENT", VARCHAR(600).</p>
  
  <p>And when I try to insert a row into the table with a simple insert query, it throws a SQLException, SQLCODE:-302 SQLSTATE:22001... , even though the length of content value does not reach the limit, 600 bytes. I tried it several times with different values and I got to know the limit bytes allowed to insert is <strong>254</strong>.</p>
  
  <p>The insert query is as follows:</p>
  
  <pre><code>INSERT INTO TBA (CONTENT) value (REPLACE(REPLACE(?, '\\n', chr(10)), '\\t', chr(09)))
  </code></pre>
  
  <p>The replace function used with the value to be inserted is required because clients is allowed to insert line feeds and tap characters out of content value they try to insert, and the content will be shown on alert messages on browser screens, using javascript.</p>
  
  <p>and the action of client layer is just submitting a POST request with a textbox element as follows:</p>
  
  <pre><code>&lt;form action="..." method="POST" name=".."&gt;
      &lt;input type="text" name="content"/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>The following is a query log written by executing the insert query with the content value that has length over 300 bytes. (the value is omitted.) It has no problem. I tried to copy-paste and execute it on DBMS tools such as TOAD and SQL Gate then it just works fine, there's no sql errors.</p>
  
  <pre><code>INSERT INTO TBA (CONTENT) value (REPLACE(REPLACE('01234567890...', '\\n', chr(10)), '\\t', chr(09)))
  </code></pre>
  
  <p>And I finally tried to remove the replace function in the query and execute it in client(browser)-server way, then I works fine at all.</p>
  
  <p>What am I missing?? the replace function could stretch the length of the value? but why it only happens when executing in client(browser)-server way?</p>
  
  <p>Please let me know.</p>