Re: JDBC and Latin1 Database problem

Поиск
Список
Период
Сортировка
От David Gagnon
Тема Re: JDBC and Latin1 Database problem
Дата
Msg-id BAY17-F378F9C2184A288174BC44CA6920@phx.gbl
обсуждение исходный текст
Ответ на Re: JDBC and Latin1 Database problem  (Oliver Jowett <oliver@opencloud.com>)
Ответы Re: JDBC and Latin1 Database problem
Список pgsql-jdbc
>From: Oliver Jowett <oliver@opencloud.com>
>To: David Gagnon <dgagnon74@hotmail.com>
>CC: pgsql-jdbc@postgresql.org
>Subject: Re: [JDBC] JDBC and Latin1 Database problem
>Date: Wed, 05 Jan 2005 15:55:21 +1300
>
>David Gagnon wrote:
>
>>To inform the jdbc driver that it must converts caracters I put the
>>following URL in my server.xml (notice the encoding=latin1).  Without this
>>variable caracter � takes 2 spaces in the latin db.  So ������ will takes
>>12 spaces.  This make my varchar(10) to small.
>
>>jdbc:postgresql://127.0.0.1:5432/webCatalog?encoding=latin1
>
>The 'encoding' parameter is only used for connections to pre-7.3 servers;
>in other cases it is ignored.

Really?! I must say that this REALLY solved my encoding problem. And I'm
using 7.4 ?!  Without this flag I always get the error describe before.

Do I have to specify something to inform the JDBC driver that it connect to
a Latin1 database?  I do get the error I described :-(


>What is the database encoding? ("SHOW server_encoding")

dgagnon@segfault dgagnon $ psql webCatalog
Welcome to psql 7.4.6, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help on internal slash commands
       \g or terminate with semicolon to execute query
       \q to quit

webCatalog=# SHOW server_encoding
webCatalog-# ;
server_encoding
-----------------
LATIN1
(1 row)

webCatalog=#


>
>>  Error executing: INSERT INTO AK  (AKNUM,AKDESC_PRI,
>>AKDESC_SEC,AKFRAIS,AKTAUX,AKTYPE) VALUES
>>('CHEQ','CH?QUE','CHEQUE',22,null,1)
>>org.postgresql.util.PSQLException: ERROR: could not convert UTF-8
>>character 0x00ef to ISO8859-1
>
>Are you constructing this entire query string yourself, or are you using a
>PreparedStatement with parameters?

This statement is read from an sql file.  So no prepare statement here is
the code that cause the problem:


          Statement statement = conn.createStatement();

          println(command);
          if (log.isDebugEnabled()) {
            log.debug(command);
          }

          boolean hasResults = false;
          if (stopOnError) {
            hasResults = statement.execute(command.toString());
          } else {
            try {
              statement.execute(command.toString());
            } catch (SQLException e) {
              e.fillInStackTrace();
              printlnError("Error executing: " + command);
              printlnError(e);
            }
          }

But this code works for 2 years without problem ... before I changed my
database encoding to Latin1 of course ...

The SQL statemetn in the corresponding file:

INSERT INTO AT (ATNUM, ATDESC_PRI, ATDESC_SEC, ATTAUX, ATNIV, ATCALC,
ATGLNUMV, ATGLNUMA) VALUES ('tvh','Taxe de vente harmonis�ePri','Taxe de
vente harmonis�e',15,0,False,'10-2090','10-2090');

Thanks for you help.  I mess with database encoding for a while now ..
Yesterday I thought I had finally fixed everything (with the encoding flag)
... It's not that simple :-(

Thanks
/David


>
>Can you show us some sample code that demonstrates the problem?
>
>-O
>
>---------------------------(end of broadcast)---------------------------
>TIP 4: Don't 'kill -9' the postmaster



В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Oliver Jowett
Дата:
Сообщение: Re: JDBC and Latin1 Database problem
Следующее
От: deepthi@granwill.com
Дата:
Сообщение: Calling a table in another database from plpgsql