Special character error in Java

1

I have a problem here and I did not find anything to solve on the internet, if you could help me, I would be extremely grateful.

Well, come on, I have a web application in java that I use Spring Boot + JSP. The problem is this: I have two applications that share the same database, one of them writes things and the other (web) reads, so far everything is ok, but when I write something from the other application that is Desktop, any something that has an accent, the bank is correct but Java can not read on the Web part and exchange for a strange character.

I've already tried:

  • Create the environment variable: JAVA_TOOL_OPTIONS with value = -Dfile.encoding=UTF8

  • Add to file .properties of Spring the line spring.datasource.connectionProperties=useUnicode=true;characterEncoding=utf-8;

  • Change the form of the bank URL: spring.datasource.url=jdbc:postgresql://localhost:5432/banco?useUnicode=true&characterEncoding=UTF-8

  • I tried to set up the POM.

  • I tried to create a filter.

  • I tried to change the character directly by the application, however, as it arrives from the database to my application in the wrong way already,

    Important information:

    The database is configured as follows:

    ENCODING = 'SQL_ASCII';
    
    LC_COLLATE = 'C';
    
    LC_CTYPE = 'C'.
    

    If I write something on the web part, I can read it again with the accent normally, however, in the database it looks something like this:

        
  • asked by anonymous 31.07.2017 / 19:18

    1 answer

    3

    First, make sure your JSPs include <meta charset="UTF-8"> within <head> of the produced HTML and before any other contents of <head> .

    In addition, in connection with PostgreSQL, you use characterEncoding=UTF-8 , but the database has been configured with ENCODING = 'SQL_ASCII'; . You should use ENCODING = 'UTF8'; . As quoted the PostgreSQL documentation :

      

    In most cases, if you are working with any non-ASCII data, it is unwise to use the SQL_ASCII setting because PostgreSQL will be unable to help you by converting or validating non-ASCII characters.

    Translating:

      

    In most cases, if you are working with any non-ASCII data, it is not a good idea to use the SQL_ASCII setting because PostgreSQL will not be able to assist you in converting or validating non-ASCII characters.

    In addition, in PostgreSQL, encoding is preferably set at the time that CREATE DATABASE is running.

        
    31.07.2017 / 19:32