title: Encoding problem from database to javamail
body: <p>I have a small application which reads from a Oracle 9i database and sends the data via e-mail, using JavaMail. The database has <code>NLS_CHARACTERSET = "WE8MSWIN1252"</code>, that's it, CP1252.</p>
  
  <p>If I run the app without any parameter, it works fine and the e-mails are sent correctly. However, I've a requeriment that enforces me to run the app with the <code>-Dfile-encoding=utf8</code> parameter, which results in the text being sent with corrupted characters.</p>
  
  <p>I've tried to change the encoding of the data read from the database, with:</p>
  
  <pre><code>String textToSend = new String(textRead.getBytes("CP1252"), "UTF-8");
  </code></pre>
  
  <p>But it doesn't help. I've tried all the possible combinations with <code>CP1252, windows-1252, ISO-8859-1</code> and <code>UTF-8</code>, but still had no luck.</p>
  
  <p>Any ideas?</p>
  
  <hr>
  
  <p><strong>Update</strong> to clarify my problem: when I do the following:</p>
  
  <pre><code>Statement stat = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
  stat.executeQuery("SELECT blah FROM blahblah ...");
  ResultSet rs = stat.getResultSet();
  String textRead = rs.getString("whatever");
  </code></pre>
  
  <p>I get <code>textRead</code> corrupted, because the database is CP1252 and the application is running in UTF-8. Another approach that I've tried but also failed:</p>
  
  <pre><code>InputStream is = rs.getBinaryStream("whatever");
  Writer writer = new StringWriter();
  char[] buffer = new char[1024];
  Reader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
  while ((n = reader.read(buffer)) != -1) {
      writer.write(buffer, 0, n);
  }
  String textRead = writer.toString();
  </code></pre>