Re: JDBC and Latin1 Database problem

From: "David Gagnon" <dgagnon74(at)hotmail(dot)com>
To: oliver(at)opencloud(dot)com
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: JDBC and Latin1 Database problem
Date: 2005-01-05 03:27:48
Message-ID: BAY17-F378F9C2184A288174BC44CA6920@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

>From: Oliver Jowett <oliver(at)opencloud(dot)com>
>To: David Gagnon <dgagnon74(at)hotmail(dot)com>
>CC: pgsql-jdbc(at)postgresql(dot)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(at)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 harmonisePri','Taxe de
vente harmonise',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

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message deepthi 2005-01-05 03:30:45 Calling a table in another database from plpgsql
Previous Message Oliver Jowett 2005-01-05 02:55:21 Re: JDBC and Latin1 Database problem