title: program throws CharConversionException in Java?
body: <p>I am getting the below mentioned error in my catch block when i print using <code>e.printStackTrace();</code>This only occurs for few records when i read it from the DB2 database. So basically only few records throw the error rest work fine. </p>
  
  <p>I have almost 1000 line of code and i am not sure were do i start from in order to understand/debug this error ? IS there any hint that i can get from the error message i should use to solve it ? </p>
  
  <pre><code>from the method getDataFromEMPHCForEmployeeDetails()----- com.ibm.db2.jcc.am.SqlException: [jcc][t4][1065][12306][3.63.123] Caught java.io.CharConversionException.  See attached Throwable for details. ERRORCODE=-4220, SQLSTATE=null
      at com.ibm.db2.jcc.am.fd.a(fd.java:663)
      at com.ibm.db2.jcc.am.fd.a(fd.java:60)
      at com.ibm.db2.jcc.am.fd.a(fd.java:112)
      at com.ibm.db2.jcc.am.ic.a(ic.java:2820)
      at com.ibm.db2.jcc.am.ic.p(ic.java:521)
      at com.ibm.db2.jcc.am.ic.N(ic.java:1558)
      at com.ibm.db2.jcc.am.vn.e(vn.java:1147)
      at com.ibm.db2.jcc.am.vn.getString(vn.java:1122)
      at com.ibm.db2.jcc.am.vn.getString(vn.java:1698)
      at CreateChart.getDataFromEMPHCForEmployeeDetails(CreateChart.java:330)
      at CreateChart.iterateDirectReportNamesFromArrayList(CreateChart.java:594)
      at CreateChart.getDataFromEMPHCForDirectReport(CreateChart.java:295)
      at CreateChart.iterateSecondLineManagerNamesFromArrayList(CreateChart.java:562)
      at CreateChart.getDataFromEMPHCForSecondLine(CreateChart.java:251)
      at CreateChart.iterateThirdLineManagerNamesFromArrayList(CreateChart.java:533)
      at CreateChart.getDataFromEMPHCForThirdLine(CreateChart.java:208)
      at CreateChart.iterateDirectorNamesFromArrayList(CreateChart.java:506)
      at CreateChart.getDataFromEMPHCForDirector(CreateChart.java:168)
      at CreateChart.iterateVPNamesFromArrayList(CreateChart.java:472)
      at CreateChart.getDataFromEMPHCForVp(CreateChart.java:126)
      at CreateChart.iterateFuncVPNamesFromArrayList(CreateChart.java:434)
      at CreateChart.getDataFromEMPHCForFuncVp(CreateChart.java:95)
      at CreateChart.main(CreateChart.java:613)
  Caused by: java.nio.charset.MalformedInputException: Input length = 186
      at com.ibm.db2.jcc.am.t.a(t.java:19)
      at com.ibm.db2.jcc.am.ic.a(ic.java:2816)
      ... 19 more
  Caused by: sun.io.MalformedInputException
      at sun.io.ByteToCharUTF8.convert(Unknown Source)
      at com.ibm.db2.jcc.am.t.a(t.java:16)
      ... 20 more
  </code></pre>
  
  <p>.</p>
  
  <pre><code>   public void getDataFromEMPHCForEmployeeDetails(String funcvp_name11, String vp_name11, String director_name11, String thirdline_name11, String secondline_name11, String directreport_name11){
  
          String myQuery11;
          if(directreport_name11 == ""){directreport_name11 = " AND DIRECT_REPORT IS NULL";}
          else{directreport_name11 =" AND DIRECT_REPORT ='"+ directreport_name11.replace("'", "''")+"'";}
  
  
          myQuery11 = "SELECT DISTINCT(SERIAL_NUM) FROM DB2INST1.EMP_HC  WHERE "+funcvp_name11+" "+vp_name11+" "+director_name11+" "+thirdline_name11+" "+ secondline_name11+""+directreport_name11;
  
  
  
          arraylistofEmployeeDetails = new ArrayList&lt;String&gt;();
  
      try {
           resultSet = st.executeQuery(myQuery11);
  
          while (resultSet.next()) 
          { 
              String SERIAL_NUM = resultSet.getString("SERIAL_NUM"); 
  
  
              if(SERIAL_NUM == null){SERIAL_NUM="";}
  
              if (SERIAL_NUM.length() &gt; 40){SERIAL_NUM = "Too Long";}
              arraylistofEmployeeDetails.add(SERIAL_NUM);
              System.out.println(SERIAL_NUM+"\n");
  
          }
  
          if(! (arraylistofEmployeeDetails.isEmpty())){
          writeEmployeeDetailsToJsonFile(arraylistofEmployeeDetails);
          }
  
      } catch (SQLException e) {
          e.printStackTrace();
  
          StringWriter wtr = new StringWriter();
          PrintWriter pwtr = new PrintWriter(wtr);
          e.printStackTrace(pwtr);
          String stackTrace = wtr.toString();
          error_logs.append("from getDataFromEMPHCForEmployeeDetails()----- "+stackTrace+"\n");
      }
  </code></pre>
  
  <p>}</p>