1

I have the following code:

stm = con.createStatement();
stm.executeUpdate("INSERT INTO city(id, name) VALUES (1, 'Chambéry');");

When I want to see the rows in my table the output is:

 id |   name   |  
----+----------+
  1 | ChambΘry |

As you can see the city name in the datatase is ChambΘry instead of Chambéry. This happens also with foreign letters like ñ, which is replaced by ± in the database.

I don't know why this is happening, both server and client encoding are UTF8, I even changed the file encoding in Netbeans to UTF8 in the netbeans.conf

I would appreciate your help

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
chris
  • 2,490
  • 4
  • 32
  • 56
  • 1
    How do you "see the rows in your table"? – Andreas Jan 01 '17 at 19:54
  • check the encoding used in your database. – davidxxx Jan 01 '17 at 19:55
  • Did you also set the project's encoding to UTF8? – brummfondel Jan 01 '17 at 19:56
  • @Andreas when I use SELECT statement I see the rows with wrong character – chris Jan 01 '17 at 19:58
  • 1
    When you use SELECT statement in *what* tool? Aka *how* do you "see the rows in your table"? Or asked another way: How do you know the it's the data in the database that's wrong, and not how you display that output? – Andreas Jan 01 '17 at 19:59
  • @davidxxx how can I see the encoding used in the db. I use `see client_encoding`for the client and `see server_encoding` for the server – chris Jan 01 '17 at 20:01
  • Have a look at [this](http://stackoverflow.com/questions/3275524/java-mysql-utf8-problem), did you set encoding for your Connection? –  Jan 01 '17 at 20:02
  • @Andreas I'm using the psql shell to see the rows – chris Jan 01 '17 at 20:03
  • @SzymonD Showing how to do it for MySQL is not really helpful for a PostgreSQL problem. – Andreas Jan 01 '17 at 20:03
  • @brummfondel I also checked the project properties in Netbeans and the encoding is UTF8 – chris Jan 01 '17 at 20:06
  • 2
    @c2J psql may not show it correctly. Try [pgAdmin](https://www.pgadmin.org/). – Andreas Jan 01 '17 at 20:08
  • Did you run the insert statement successfully in psql? – brummfondel Jan 01 '17 at 20:09
  • @c2j You could also check this out [this](https://jdbc.postgresql.org/documentation/80/connect.html). There is a charSet parameter that you can add on the connection string. – Stamatis Liatsos Jan 01 '17 at 20:12
  • If possible try to use pgadmin 3 (https://www.pgadmin.org/download/) - not 4, 4 is ugly. IT gives you many details of database settings, encodings and more just by simple menus – brummfondel Jan 01 '17 at 20:15
  • it shows correctly in pgAdmin, and if I execute a SELECT statement from my java project it also has the right characters. But why can I not see the same the same characters from the psql shell even when I am setting the `client_encoding` to UTF8 in the shell? I also want to be able to insert from the shell and show those records correctly in pgAdmin – chris Jan 01 '17 at 20:46
  • It would help if you mentioned what shell you are talking about. (Hint: If it's the Windows command prompt then it doesn't handle Unicode characters particularly well.) – Gord Thompson Jan 02 '17 at 02:35
  • 2
    At a guess you're on Windows and should set the Unicode codepage. See the psql manual. – Craig Ringer Jan 02 '17 at 05:01
  • I tried to follow the steps in this [question](http://stackoverflow.com/questions/20952893/postgresql-encoding-problems-on-windows-when-using-psql-command-line-utility) but still, I can't get the Windows cmd to show the correct characters – chris Jan 02 '17 at 18:07

0 Answers0