title: Search java string for 'special' characters before inserting into derbyDB varchar field
body: <p>I am trying to convert from MS Access to DerbyDB. However some varchar fields have 'special' characters, such as newlines, tabs, percent marks, foreign characters etc.</p>
  
  <p>I created a quick method...</p>
  
  <pre><code>public String charCheck(String s)
  {
  
  
      errLog.add(1, "converting string from " + s);
      s.replaceAll("'", "''");//an apostrophe is escaped with an apostrophy in Derby...
      s.replaceAll("%", "\\%");//a percent sign
      s.replaceAll("\\s+n", " ");//whitespace characters (newlines and tabs etc)
      s.replaceAll("/", "\\/");//the 'divide' \ character, 
      s.replaceAll("&lt;", "\\&lt;");//mathematical symbol less than
      s.replaceAll("&gt;", "\\&gt;");//mathematical symbol greater than
      errLog.add(1, "to " + s);
  
      return s;
  }//end method
  </code></pre>
  
  <p>Which I run whenever I determine that I need a varchar (or long varchar) data type. The strange thing is that my error log prints out the messages, but in the output whitespace characters do not appear to change (ie tabs and new lines, do not get converted to a simple space) and any apostrophe in the string is not replaced.</p>
  
  <p>a sample of the output of this method produces the following.</p>
  
  <pre><code>converting string from 2.   FIN DE L’ESSAI
  to 2.   FIN DE L’ESSAI
  </code></pre>
  
  <p>So the string remains obviously unchanged, which upsets derbyDB when I run the insert statement, also I am not finding any obvious documentation on the escape sequence for inserting multiple records into a table, I would like to use a statement then add the escape keyword after it, ie</p>
  
  <pre><code>stmt.execute("{call "+ sqlInsertStatement +"}{escape '" + escapeCharacter +"'" );
  </code></pre>
  
  <p>I also read from the docs that the <em>escape</em> keyword may not be usefull in the above statement, if so how can I te</p>
  
  <p>I need to know where to go to sort the insert error that I get.</p>
  
  <p>If I copy and past the insert statement directly into ij, then remove the special characters the record will insert fine, I just don't understand why it isn't being converted in the first instance.</p>
  
  <p>I have also tried surrounding varchar and longvarchar fields with double quotes, but again derby kicks out an error saying that a double quote was found!</p>
  
  <p>I want to get this sorted as I feel like I am so close...</p>
  
  <p>Thanks in advance</p>