pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: carmentl12 <hrodriguez@facinf.uho.edu.cu>
To: pgsql-jdbc@postgresql.org
Subject: Problem with client_encoding UTF8
Date: Fri, 24 Aug 2012 11:02:49 -0700 (PDT)
Message-ID: <1345831369323-5721132.post@n5.nabble.com> (raw)

Hello:

I'm trying to restore a postgres database backup programmatically, I use
JDBC driver (postgresql-9.1-902.jdbc4), and I get the following error, 

org.postgresql.util.PSQLException: The server's client_encoding parameter
was changed to UTF8. The JDBC driver requires client_encoding to be UNICODE
for correct operation.
at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1366)
	at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:192)
	at
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:451)
	at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:350)
	at
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:343)


This is my code:
PreparedStatement preparedStatement;

String content = getScriptContents("C:/script.sql"); //here I read the
contents of the script
String[] statements = content.split(";");

//here I execute with preparedStatement each script line, the error shows in
this line
//SET client_encoding = 'UTF8';

   for (String string : statements) {
         if (!string.equals("")) {
              preparedStatement =
currentConnection.getJDBCConnection().prepareStatement(string);
              preparedStatement.execute();
              preparedStatement.close();
                        }
         }

The database where I want to restore has as encoding UTF8, so I don't know
why appears this error.

I read this posts, but I'm not clear what is the solution that any of you
proposed for this problem:
http://archives.postgresql.org/pgsql-jdbc/2008-02/msg00175.php
http://postgresql.1045698.n5.nabble.com/SET-client-encoding-UTF8-td2174216.html
http://postgresql.1045698.n5.nabble.com/Re-HACKERS-JDBC-connections-to-9-1-td4310977.html

In the third post it is proposed a patch but I'm not sure if this solve the
error and it seems hasn't been included in the driver after all, please I
would really appreciatte if you tell me why this is happening and which is
the solution for it.

One curious thing, I made a test creating the connection like this, and the
error didn't appear, the restore was successful. 
Connection connection =
DriverManager.getConnection("jdbc:postgresql://192.168.2.241:5432/demo_desktop",
"user", "pass");

Before I used for create the connection this class
org.netbeans.api.db.explorer.DatabaseConnection (from NetBeans Platform), I
don't understand why with this one appears the error and with
DriverManager.getConnection doesn't.

Thanks in advance,
Carmen




--
View this message in context: http://postgresql.1045698.n5.nabble.com/Problem-with-client-encoding-UTF8-tp5721132.html
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.




view thread (2+ messages)  latest in thread

Message-ID: <1345831369323-5721132.post@n5.nabble.com>
Permalink:  ../1345831369323-5721132.post@n5.nabble.com/
Also on:    postgresql.org/message-id/1345831369323-5721132.post@n5.nabble.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: hrodriguez@facinf.uho.edu.cu
  Subject: Re: Problem with client_encoding UTF8
  In-Reply-To: <1345831369323-5721132.post@n5.nabble.com>
  References: <1345831369323-5721132.post@n5.nabble.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox