title: Invalid characters using Oracle 12c and ojdbc7 / ojdbc8 driver
body: <p>After persisting data through our REST API in Oracle 12c database the special characters are not recognized (they appear as weird characters) when selecting the data from the database.</p>
  
  <p>Could it be Oracle Database configuration? I'll add all the data here:</p>
  
  <ul>
  <li>Oracle version: 12.1.0.2.0</li>
  <li>Java Driver version: ojdbc7-12.1.0.1.jar (latest available)</li>
  <li>Java version: JDK 8u162 (latest available)</li>
  <li>Application Server: WildFly 9.0.1</li>
  </ul>
  
  <p>If we downgrade the driver to OJDBC 6 and it works for some characters that were already present in the database.</p>
  
  <p>We've also added the <code>orai18n.jar</code> driver into the JBoss classpath but nothing changed.</p>
  
  <h2>Oracle Database NLS configuration</h2>
  
  <p><a href="https://i.stack.imgur.com/gYK6V.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gYK6V.png" alt="enter image description here"></a></p>
  
  <h2>POST</h2>
  
  <p>Very simple post operation with JSON payload:</p>
  
  <p><a href="https://i.stack.imgur.com/AX9cy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AX9cy.png" alt="enter image description here"></a></p>
  
  <h2>GET</h2>
  
  <p>After inserting into the database we get the data but we are not able to see the special characters:</p>
  
  <p><a href="https://i.stack.imgur.com/NeDME.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NeDME.png" alt="enter image description here"></a></p>
  
  <p>Update: I've added another column with type <code>NVARCHAR2</code>, got this in response:</p>
  
  <p><a href="https://i.stack.imgur.com/bMGGl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bMGGl.png" alt="enter image description here"></a></p>
  
  <h2>Code</h2>
  
  <p>We isolated the problem in this simple project with a simple REST service class. We considered that Hibernate could be the cause but we have implemented a pure JDBC API and we got the same results.</p>
  
  <pre><code>@Path("/parameter")
  @Stateless
  public class ParameterResource {
  
      @PersistenceContext
      private EntityManager em;
  
      @POST
      public void post(Parameter p) throws Exception {
          System.out.println("Value on POST: " + p.getValue());
          em.persist(p);
      }
  
      @GET
      @Path("/{id}")
      public Parameter get(@PathParam("id") String id) throws Exception {
          Parameter p = em.find(Parameter.class, id);
          System.out.println("Value on GET: " + p.getValue());
          return p;
      }
  
  }
  </code></pre>
  
  <p>Table DDL is the following:</p>
  
  <pre><code>Name   Null?    Type
  ------ -------- -------------- 
  ID     NOT NULL VARCHAR2(20)   
  VALUE           VARCHAR2(200)  
  VALUEN          NVARCHAR2(200) 
  </code></pre>
  
  <p>Console output is the following, so there should be no problem with the REST API because data seems to be "corrupted" right at the database interface:</p>
  
  <p><a href="https://i.stack.imgur.com/VL1ZW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VL1ZW.png" alt="enter image description here"></a></p>
  
  <p>Even added a filter to make sure we were using the correct encoding back and forth the Web services.</p>
  
  <pre><code>@WebFilter("myFilter")
  public class MyFilter implements Filter {
  
      @Override
      public void init(FilterConfig filterConfig) throws ServletException {
      }
  
      @Override
      public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
              throws IOException, ServletException {
          request.setCharacterEncoding("UTF-8");
          response.setCharacterEncoding("UTF-8");
          chain.doFilter(request, response);
      }
  
      @Override
      public void destroy() {
      }
  
  }
  </code></pre>
  
  <h2>SQL Developer</h2>
  
  <p>The problem is also happening when using SQL Developer, which happens to run on Java and uses OJDBC 8 driver to connect.</p>
  
  <p><a href="https://i.stack.imgur.com/Y0AtM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Y0AtM.png" alt="enter image description here"></a></p>